Skip to content

Commit 2eea22a

Browse files
committed
Merge branch 'feature-testng-7.5' into testng-7.5/3.2.11.x
2 parents 40fa62a + f98f3b9 commit 2eea22a

File tree

6 files changed

+19
-29
lines changed

6 files changed

+19
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ ScalaTest + TestNG provides integration support between ScalaTest and TestNG.
33

44
**Usage**
55

6-
To use it for ScalaTest 3.2.9 and TestNG 6.7.x:
6+
To use it for ScalaTest 3.2.11 and TestNG 6.7.x:
77

88
SBT:
99

1010
```
11-
libraryDependencies += "org.scalatestplus" %% "testng-6-7" % "3.2.9.0" % "test"
11+
libraryDependencies += "org.scalatestplus" %% "testng-6-7" % "3.2.11.0" % "test"
1212
```
1313

1414
Maven:
@@ -17,7 +17,7 @@ Maven:
1717
<dependency>
1818
<groupId>org.scalatestplus</groupId>
1919
<artifactId>testng-6-7_2.13</artifactId>
20-
<version>3.2.9.0</version>
20+
<version>3.2.11.0</version>
2121
<scope>test</scope>
2222
</dependency>
2323
```

build.sbt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import java.io.PrintWriter
22
import scala.io.Source
33

4-
name := "testng-6.7"
4+
name := "testng-7.5"
55

66
organization := "org.scalatestplus"
77

8-
version := "3.2.10.0"
8+
version := "3.2.11.0"
99

1010
homepage := Some(url("https://github.com/scalatest/scalatestplus-testng"))
1111

@@ -31,10 +31,10 @@ scalaVersion := "2.13.6"
3131
crossScalaVersions := List("2.10.7", "2.11.12", "2.12.15", "2.13.6", "3.0.2")
3232

3333
libraryDependencies ++= Seq(
34-
"org.scalatest" %% "scalatest-core" % "3.2.10",
35-
"org.testng" % "testng" % "6.7",
34+
"org.scalatest" %% "scalatest-core" % "3.2.11",
35+
"org.testng" % "testng" % "7.5",
3636
"commons-io" % "commons-io" % "1.3.2" % "test",
37-
"org.scalatest" %% "scalatest-funsuite" % "3.2.10" % "test"
37+
"org.scalatest" %% "scalatest-funsuite" % "3.2.11" % "test"
3838
)
3939

4040
Compile / packageDoc / publishArtifact := !scalaBinaryVersion.value.startsWith("3")

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.5.5
1+
sbt.version=1.5.8

src/main/scala/org/scalatestplus/testng/SingleTestAnnotationTransformer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import java.lang.reflect.Constructor
2525
// Probably might work as private[testng], but not sure and right before the release.
2626
private[testng] class SingleTestAnnotationTransformer(testName: String) extends IAnnotationTransformer {
2727
override def transform( annotation: ITestAnnotation, testClass: java.lang.Class[_], testConstructor: Constructor[_], testMethod: Method): Unit = {
28-
if (testName == testMethod.getName)
28+
if (testName != testMethod.getName)
2929
annotation.setGroups(Array("org.scalatestplus.testng.singlemethodrun.methodname"))
3030
}
3131
}

src/main/scala/org/scalatestplus/testng/TestNGSuiteLike.scala

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import TestNGHelper.getIndentedTextForTest
2626
import TestNGHelper.yeOldeTestNames
2727
import org.scalatest.tools.Utils.wrapReporterIfNecessary
2828
import events.MotionToSuppress
29+
import scala.collection.JavaConverters._
2930

3031
/**
3132
* Implementation trait for class <code>TestNGSuite</code>, which represents
@@ -281,20 +282,9 @@ trait TestNGSuiteLike extends Suite { thisSuite =>
281282
// NOTE: There was another option - we could TestNG's XmlSuites to specify which method to run.
282283
// This approach was about as much work, offered no clear benefits, and no additional problems either.
283284

284-
// Using reflection because TestNG has a incompatible change, we want to allow people to use the old and the new version of TestNG.
285-
try {
286-
val transformerSuperClass = Class.forName("org.testng.IAnnotationTransformer")
287-
val transformerSubClass = Class.forName("org.scalatestplus.testng.SingleTestAnnotationTransformer")
288-
// Go with TestNG 6
289-
val transformerInstance = transformerSubClass.getConstructor(classOf[String]).newInstance(testName).asInstanceOf[SingleTestAnnotationTransformer]
290-
testng.setGroups("org.scalatestplus.testng.singlemethodrun.methodname")
291-
val method = testng.getClass.getMethod("setAnnotationTransformer", transformerSuperClass)
292-
method.invoke(testng, transformerInstance)
293-
}
294-
catch {
295-
case e: ClassNotFoundException =>
296-
new UnsupportedOperationException("Sorry, due to incompatible changes in TestNG, running a single test is only supported in TestNG version 6 or later.", e)
297-
}
285+
val transformer = new SingleTestAnnotationTransformer(testName)
286+
testng.setGroups("org.scalatestplus.testng.singlemethodrun.methodname")
287+
testng.addListener(transformer)
298288
}
299289

300290
/*
@@ -341,13 +331,14 @@ trait TestNGSuiteLike extends Suite { thisSuite =>
341331
}
342332

343333
/**
344-
* TestNG's onTestSkipped maps cleanly to TestIgnored. Again, simply build
334+
* TestNG's onTestSkipped maps cleanly to TestCanceled. Again, simply build
345335
* a report and pass it to the Reporter.
346336
*/
347337
override def onTestSkipped(result: ITestResult): Unit = {
348338
val testName = result.getName + params(result)
349339
val formatter = getIndentedTextForTest(testName, 1, true)
350-
report(TestIgnored(tracker.nextOrdinal(), thisSuite.suiteName, thisSuite.getClass.getName, Some(thisSuite.getClass.getName), testName, testName, Some(formatter), getTopOfMethod(thisSuite.getClass.getName, result.getName)))
340+
val causedBy = result.getSkipCausedBy().asScala.map(_.getMethodName())
341+
report(TestCanceled(tracker.nextOrdinal(), "Skipped caused by ", thisSuite.suiteName, thisSuite.getClass.getName, Some(thisSuite.getClass.getName), testName, testName, Vector.empty))
351342
}
352343

353344
/**

src/test/scala/org/scalatestplus/testng/TestNGSuiteSuite.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package org.scalatestplus.testng {
1919
import org.scalatest.events._
2020
import org.scalatestplus.testng.testpackage._
2121
import org.scalatest.fixture
22-
import org.hamcrest.core.IsAnything
2322
import org.scalatestplus.testng.SharedHelpers.EventRecordingReporter
2423

2524
class TestNGSuiteSuite extends funsuite.AnyFunSuite {
@@ -83,9 +82,9 @@ import org.scalatestplus.testng.SharedHelpers.EventRecordingReporter
8382
status.setCompleted()
8483

8584
assert(reporter.suiteStartingEventsReceived.isEmpty)
86-
assert(reporter.testStartingEventsReceived.length == 1)
85+
assert(reporter.testStartingEventsReceived.length == 2)
8786
assert(reporter.testFailedEventsReceived.length == 1)
88-
assert(reporter.testIgnoredEventsReceived.length == 1)
87+
assert(reporter.testCanceledEventsReceived.length == 1)
8988
assert(reporter.suiteCompletedEventsReceived.isEmpty)
9089
}
9190

0 commit comments

Comments
 (0)