@@ -26,6 +26,7 @@ import TestNGHelper.getIndentedTextForTest
26
26
import TestNGHelper .yeOldeTestNames
27
27
import org .scalatest .tools .Utils .wrapReporterIfNecessary
28
28
import events .MotionToSuppress
29
+ import scala .collection .JavaConverters ._
29
30
30
31
/**
31
32
* Implementation trait for class <code>TestNGSuite</code>, which represents
@@ -281,20 +282,9 @@ trait TestNGSuiteLike extends Suite { thisSuite =>
281
282
// NOTE: There was another option - we could TestNG's XmlSuites to specify which method to run.
282
283
// This approach was about as much work, offered no clear benefits, and no additional problems either.
283
284
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)
298
288
}
299
289
300
290
/*
@@ -341,13 +331,14 @@ trait TestNGSuiteLike extends Suite { thisSuite =>
341
331
}
342
332
343
333
/**
344
- * TestNG's onTestSkipped maps cleanly to TestIgnored . Again, simply build
334
+ * TestNG's onTestSkipped maps cleanly to TestCanceled . Again, simply build
345
335
* a report and pass it to the Reporter.
346
336
*/
347
337
override def onTestSkipped (result : ITestResult ): Unit = {
348
338
val testName = result.getName + params(result)
349
339
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))
351
342
}
352
343
353
344
/**
0 commit comments