How to ensure that test is executed after all tests in scalatest? - scalatest

I want to test that all methods of a REST API are covered by tests.
All http calls are recorded into a mutable set, and I have a piece of code that checks correspondence between specification and the result set of recored api calls.
I can place this check in a separate test at the end of FunSuite and it would be executed after all other tests. However, there are two problems: I have to copy-paste it in every file that tests API and make sure it is at the end of file.
Using common trait does not work: tests from parent class are executed before tests from child class. Placing the test inside afterAll does not work either: scalatest swallows all exceptions (including test failures) thrown in it.
Is there a way to run some test after all others without boilerplate?

Personally I would go with dedicated coverage tool such as scoverage. One advantage would be avoiding global state.
Nevertheless, as per question, a way to execute test after all tests would be via Suites and BeforeAndAfterAll traits like so
import org.scalatest.{BeforeAndAfterAll, Suites, Matchers}
class AllSuites extends Suites(
new FooSpec,
new BarSpec,
) with BeforeAndAfterAll withy Matchers {
override def afterAll(): Unit = {
// matchers here as usual
}
}
Here is a toy example with global state as per question
AllSuites.scala
import org.scalatest.{BeforeAndAfterAll, Matchers, Suites}
object GlobalMutableState {
val set = scala.collection.mutable.Set[Int]()
}
class AllSuites extends Suites(
new HelloSpec,
new GoodbyeSpec
) with BeforeAndAfterAll with Matchers {
override def afterAll(): Unit = {
GlobalMutableState.set should contain theSameElementsAs Set(3,2)
}
}
HelloSpec.scala
#DoNotDiscover
class HelloSpec extends FlatSpec with Matchers {
"The Hello object" should "say hello" in {
GlobalMutableState.set.add(1)
"hello" shouldEqual "hello"
}
}
GoodbyeSpec.scala
#DoNotDiscover
class GoodbyeSpec extends FlatSpec with Matchers {
"The Goodbye object" should "say goodbye" in {
GlobalMutableState.set.add(2)
"goodbye" shouldEqual "goodbye"
}
}
Now executing sbt test gives something like
[info] example.AllSuites *** ABORTED ***
[info] HashSet(1, 2) did not contain the same elements as Set(3, 2) (AllSuites.scala:15)
[info] HelloSpec:
[info] The Hello object
[info] - should say hello
[info] GoodbyeSpec:
[info] The Goodbye object
[info] - should say goodbye
[info] Run completed in 377 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 2, aborted 1
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] *** 1 SUITE ABORTED ***
[error] Error during tests:
[error] example.AllSuites
[error] (Test / test) sbt.TestsFailedException: Tests unsuccessful

Related

OptaPlanner benchmarking won't run

I'm trying to run an OptaPlanner benchmark with the following configuration:
<?xml version="1.0" encoding="UTF-8"?>
<plannerBenchmark xmlns="https://www.optaplanner.org/xsd/benchmark" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.optaplanner.org/xsd/benchmark https://www.optaplanner.org/xsd/benchmark/benchmark.xsd">
<benchmarkDirectory>data/acme</benchmarkDirectory>
<inheritedSolverBenchmark>
<solver>
<solutionClass>org.acme.domain.Main</solutionClass>
<entityClass>org.acme.domain.Standstill</entityClass>
<entityClass>org.acme.domain.Visit</entityClass>
<scoreDirectorFactory>
<constraintProviderClass>org.acme.solver.MainConstraintProvider</constraintProviderClass>
<initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
</scoreDirectorFactory>
<termination>
<secondsSpentLimit>30</secondsSpentLimit>
</termination>
</solver>
<problemBenchmarks>
<solutionFileIOClass>org.acme.bootstrap.AcmeSolutionIO</solutionFileIOClass>
<inputSolutionFile>data/latest.xml</inputSolutionFile>
</problemBenchmarks>
</inheritedSolverBenchmark>
<solverBenchmark>
<solver>
<constructionHeuristic>
<constructionHeuristicType>FIRST_FIT</constructionHeuristicType>
</constructionHeuristic>
<localSearch>
<localSearchType>LATE_ACCEPTANCE</localSearchType>
</localSearch>
</solver>
</solverBenchmark>
</plannerBenchmark>
However, I get this error message:
Exception in thread "main" org.optaplanner.benchmark.api.PlannerBenchmarkException: Benchmarking failed: failureCount (1). The exception of the firstFailureSingleBenchmarkRunner (blankData_Config_0_0) is chained.
at org.optaplanner.benchmark.impl.DefaultPlannerBenchmark.benchmarkingEnded(DefaultPlannerBenchmark.java:326)
at org.optaplanner.benchmark.impl.DefaultPlannerBenchmark.benchmark(DefaultPlannerBenchmark.java:100)
at org.optaplanner.benchmark.impl.DefaultPlannerBenchmark.benchmarkAndShowReportInBrowser(DefaultPlannerBenchmark.java:424)
at org.acme.bootstrap.BenchmarkApp.main(BenchmarkApp.kt:29)
Caused by: java.lang.IllegalStateException: The class (class java.lang.Long) should have a no-arg constructor to create a planning clone.
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner.lambda$retrieveCachedConstructor$0(FieldAccessingSolutionCloner.java:90)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
at org.optaplanner.core.impl.domain.common.ConcurrentMemoization.computeIfAbsent(ConcurrentMemoization.java:44)
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner.retrieveCachedConstructor(FieldAccessingSolutionCloner.java:85)
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner$FieldAccessingSolutionClonerRun.constructClone(FieldAccessingSolutionCloner.java:158)
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner$FieldAccessingSolutionClonerRun.clone(FieldAccessingSolutionCloner.java:150)
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner$FieldAccessingSolutionClonerRun.process(FieldAccessingSolutionCloner.java:207)
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner$FieldAccessingSolutionClonerRun.processQueue(FieldAccessingSolutionCloner.java:194)
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner$FieldAccessingSolutionClonerRun.cloneSolution(FieldAccessingSolutionCloner.java:136)
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner.cloneSolution(FieldAccessingSolutionCloner.java:73)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.cloneSolution(AbstractScoreDirector.java:257)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.cloneWorkingSolution(AbstractScoreDirector.java:250)
at org.optaplanner.core.impl.solver.recaller.BestSolutionRecaller.updateBestSolutionAndFire(BestSolutionRecaller.java:129)
at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.phaseEnded(DefaultConstructionHeuristicPhase.java:146)
at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solve(DefaultConstructionHeuristicPhase.java:98)
at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:99)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:192)
at org.optaplanner.benchmark.impl.SubSingleBenchmarkRunner.call(SubSingleBenchmarkRunner.java:122)
at org.optaplanner.benchmark.impl.SubSingleBenchmarkRunner.call(SubSingleBenchmarkRunner.java:42)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NoSuchMethodException: java.lang.Long.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3585)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2754)
at org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner.lambda$retrieveCachedConstructor$0(FieldAccessingSolutionCloner.java:88)
... 22 more
I've tried many other benchmark configs including with <solverBenchmarkBluePrintType>CONSTRUCTION_HEURISTIC_WITH_AND_WITHOUT_LOCAL_SEARCH</solverBenchmarkBluePrintType> but none of them work either.
I had it working previously, but I went back to it after a number of changes and it no longer works.
I'm using a SimpleLongScore now instead of a SimpleScore and I'm wondering if that has anything to do with the error since before it wasn't throwing this exception.
Any ideas?
Edit #1:
I wish I could provide more code, but I really don't know what code to include.
The bizarre thing is that OptaPlanner runs just fine through mvn compile quarkus:dev, but when I run my benchmark app, from the main entry, it gives the errors as mentioned before, java.lang.IllegalStateException: The class (class java.lang.Long) should have a no-arg constructor to create a planning clone.
Here's my main:
fun main(args: Array<String>) {
val plannerBenchmarkFactory:PlannerBenchmarkFactory = PlannerBenchmarkFactory.createFromXmlResource("benchmarkBluePrintConfig.xml")
val plannerBenchmark: PlannerBenchmark = plannerBenchmarkFactory.buildPlannerBenchmark()
plannerBenchmark.benchmarkAndShowReportInBrowser()
}
The solverConfig.xml can also be the same for both, but only the benchmark app throws the error. It's pretty odd to me.
I figured it out.
In my Visit class I was using a #CustomShadowVariable:
#DeepPlanningClone
#CustomShadowVariable(
variableListenerClass = ArrivalTimeUpdatingVariableListener::class,
sources = [PlanningVariableReference(variableName = "previousStandstill")]
)
var arrivalTime: Long? = null
Removing #DeepPlanningClone solved the problem.
I have no idea why it runs fine when the SolverManager is #Inject'd as opposed to throwing the error when SolverConfig/SolverManager is created through the API (as it is in my Benchmark App).

How to generate Cucumber extent reports 4 through Gradle

I am executing the Cucumber automation test scripts through gradle, though i am able to execute the test successfully but reports are not getting generated. I did give a try with with below gradle tasks
one at a time.
Cucumber gradle tasks copied below
a) for the below gradle task i am able to execute the scripts which does not generate reports as i have not included the reports statements inside args
task cucumber() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty',
'--glue','com.hal.brands.test.stepdefinition',
'src/test/resources','src/main/java',
'--tags', '#Api'
]
}
}
}
b) I tried to include the few statements related to reporting as shown in below gradle task but it failed with a exception
task cucumber() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', 'json:target/HalBrands.json', 'com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:',
'--monochrome', 'true',
'--features','src\test\resources\featurefile',
'--glue','com.hal.brands.test.stepdefinition',
'src/test/resources','src/main/java',
'--tags', '#Api'
]
}
}
}
Exception details given below
BUILD SUCCESSFUL in 1s
6 actionable tasks: 6 up-to-date
E:\GradleProj_workspace\GadleDemoProj>gradle cucumber
> Configure project :
http://api-qa.dpr-prv.halbrands.us.cloudappzero.azureflash.com
E:\GradleProj_workspace\GadleDemoProj
> Task :cucumber FAILED
Exception in thread "main" java.lang.IllegalArgumentException: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter: is not valid. Try URI[:LINE]*
at io.cucumber.core.model.FeatureWithLines.parse(FeatureWithLines.java:56)
at io.cucumber.core.options.RuntimeOptionsParser.parse(RuntimeOptionsParser.java:131)
at io.cucumber.core.options.CommandlineOptionsParser.parse(CommandlineOptionsParser.java:25)
at io.cucumber.core.options.CommandlineOptionsParser.parse(CommandlineOptionsParser.java:29)
at io.cucumber.core.cli.Main.run(Main.java:29)
at io.cucumber.core.cli.Main.main(Main.java:14)
Caused by: java.lang.IllegalArgumentException: Expected scheme-specific part at index 68: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:
at java.net.URI.create(URI.java:852)
at io.cucumber.core.model.FeaturePath.parseProbableURI(FeaturePath.java:72)
at io.cucumber.core.model.FeaturePath.parse(FeaturePath.java:57)
at io.cucumber.core.model.FeatureWithLines.parseFeaturePath(FeatureWithLines.java:77)
at io.cucumber.core.model.FeatureWithLines.parse(FeatureWithLines.java:53)
... 5 more
Caused by: java.net.URISyntaxException: Expected scheme-specific part at index 68: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.failExpecting(URI.java:2854)
at java.net.URI$Parser.parse(URI.java:3057)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)
... 9 more
FAILURE: Build failed with an exception.
* Where:
Build file 'E:\GradleProj_workspace\GadleDemoProj\build.gradle' line: 104
* What went wrong:
Execution failed for task ':cucumber'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_202\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
6 actionable tasks: 1 executed, 5 up-to-date
E:\GradleProj_workspace\GadleDemoProj>
**---------------------------------------------------------------------------------------------------------------**
I am not sure where i am going wrong in the above 'b' gradle task . Please help with me at the earliest as iam literally wasting lot of time here trying out many possibilities. Also i want to keep you informed that i am new gradle stuff.
Have also copied cucumberoptions as present in my cucumber runner file
#CucumberOptions(features = { "classpath:featurefile" }, glue = { "classpath:com.hal.brands.test.stepdefinition",
"classpath:com.hal.brands.helper" },
plugin = { "pretty", "json:target/HalBrands.json", "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:" },
monochrome = true, tags = "#Api")
Pls take off the json: to get rid of the exception you are getting wrt to invalid scheme!
The Complete solution is given below .
task cucumber() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty',
'--plugin', 'json:target/HalBrands.json',
'--plugin', 'com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:Report',
'--glue','com.hal.brands.test.stepdefinition',
'src/test/resources','src/main/java',
'--tags', '#Api'
]
}
}
}

In gatling, I got an error with "Exception in thread "main" java.lang.ExceptionInInitializerError"

When I run Engine.scala under the scala directory,it gives an error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at Engine$.delayedEndpoint$Engine$1(Engine.scala:7)
at Engine$delayedInit$body.apply(Engine.scala:4)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:389)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at Engine$.main(Engine.scala:4)
at Engine.main(Engine.scala)
Caused by: java.lang.NullPointerException
at io.gatling.commons.util.PathHelper$.url2path(PathHelper.scala:34)
at IDEPathHelper$.<init>(IDEPathHelper.scala:7)
at IDEPathHelper$.<clinit>(IDEPathHelper.scala)
... 11 more
And BaiduHomePageSimulation.scala is:
package test.scala
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class BaiduSimulation extends Simulation {
// Set the root path of the request
val httpConf = http.baseUrl("https://www.baidu.com")
/*
run 10 seconds, during:the default unit is seconds, if you want to use microseconds eg. during(100 millisecond)
*/
val scn = scenario("BaiduSimulation").during(10){
exec(http("baidu_home").get("/"))
}
// set the thread count
setUp(scn.inject(atOnceUsers(10)).protocols(httpConf))
}
I don't konw how to fix it? Has anyone encountered a similar issue?
I was getting this error and was able to resolve it by marking the scala directory as Test Sources Root
Right click scala folder > Mark directory as > Test Sources Root

Spec is missing in Allure report if an error occurred in setup methods

In my GEB + Selenium Webdriver tests there are some UI actions in setupSpec() methods (common case, I believe). The problem is that if there is an exception in those steps, the whole spec is completely missing in the final report, but it's logical to see the tests of that spec marked as ignored in the report.
This is a real problem, because the build can pass with the success percentage of 100%, despite there are tests which didn't start.
A \build\allure-results\<id>-result.json file is not generated for that spec.
Here is the example to reproduce the issue:
Spec #1 (With an exception, expected to be shown as ignored):
#Stepwise
#Feature("Job")
#Story("Spec with exception in setup")
class SetupExceptionTest extends GebReportingSpec {
def setupSpec() {
println 'in setup spec'
throw new ElementNotInteractableException('some error')
}
def 'Test 1'() {
setup:
println 'in test 1'
expect:
2 == 2
}
def 'Test 2'() {
setup:
println 'in test 2'
expect:
2 == 3
}
def cleanupSpec() {}
}
Spec #2 (With no exception in setup):
#Stepwise
#Feature("Job")
#Story("Spec with no exception in setup")
class SetupTest extends GebReportingSpec {
def setupSpec() {
println 'in setup spec'
}
def 'Test 1'() {
setup:
println 'in test 1'
expect:
2 == 2
}
def 'Test 2'() {
setup:
println 'in test 2'
expect:
2 == 3
}
def cleanupSpec() {}
}
The launch command: gradlew clean test -PignoreTestFailures=true allureServe produces the following report:
So there is no SetupExceptionTest spec in any of report sections.
Are there any settings to change this behavior? Or maybe known workarounds?
The following versions used:
testCompile group: 'org.spockframework', name: 'spock-core', version: '1.2-groovy-2.4'
testCompile group: 'io.qameta.allure', name: 'allure-spock', version: '2.7.0'
I never used Allure reports before, gave it a quick spin with the latest version allure-spock 2.12.1 and Spock 1.3-groovy-2.5 in my Maven project. Maven test run fails because there seems to be a dependency missing, but when I run the two tests from my IDE, the test get executed at least.
As you said, I also see [UUID]-result.json files being generated for SetupTest but not for SetupExceptionTest. So if Allure does not create these files in case of a test setup error, no fancy HTML report can be generated either. This looks like an Allure problem to me, either in Allure core or in the Spock integration.
What happens for JUnit tests? Do they behave the same or differently?
In any case, if I comment out the Allure annotations in your tests and run them with Maven Surefire, there is a report generated for SetupExceptionTest, which means that neither Spock nor Maven are the problem. I think you ought to look at Allure because by elimination this is the only remaining component in the tool chain.
Below is a workaround I used.
In the base class:
#Shared
protected Throwable setupSpecThrowable
def setup() {
if (setupSpecThrowable) {
throw setupSpecThrowable
}
}
def cleanupSpec() {
setupSpecThrowable = null
}
protected def withSetupErrorCatch(Closure closure) {
try {
closure()
} catch (Throwable t) {
setupSpecThrowable = t
}
}
In each test class:
def setupSpec() {
def data = getSetupSpecData()
withSetupErrorCatch {
//actions that can throw something
}
}
This catches any exception in setupSpec() and throws it in setup() so that allure can see and record the test.

Set the test name for DynamicTest

I'm leveraging the DynamicTest functionality of JUnit 5.3.0-M1 and there's a showstopping point I can't seem to figure out with regards to the test name.
My expectation (right or wrong) is that the displayName of the DynamicTest translates to what I'm used to seeing as the test name in the test output.
For example, given the following TestFactory method
public class RequestAcceptTest {
private final Proxy.Location proxy = Proxy.location();
#TestFactory
Collection<DynamicTest> testAllMimeTypes() {
final List<DynamicTest> tests = new ArrayList<>();
for (final Method method : Method.values()) {
for (final MimeType mimeType : MimeType.values()) {
final String displayName = String.format("testAccept%svia%s", mimeType.name(), method);
tests.add(dynamicTest(displayName, () -> {
assertAccept(200, method, mimeType);
}));
}
}
return tests;
}
I would expect to see failures output by maven-surefire-plugin contain the DynamicTest displayName somewhere, possibly like so:
[ERROR] Tests run: 6, Failures: 6, Errors: 0, Skipped: 0, Time elapsed: 1,578.898 s <<< FAILURE! - in com.example.prototype.proxy.RequestAcceptTest
[ERROR] testAcceptApplicationJsonviaGET Time elapsed: 0.013 s <<< FAILURE!
org.opentest4j.AssertionFailedError
at com.example.prototype.proxy.RequestAcceptTest.assertAccept(RequestAcceptTest.java:73)
at com.example.prototype.proxy.RequestAcceptTest.lambda$testAllMimeTypes$0(RequestAcceptTest.java:64)
[ERROR] testAcceptApplicationJsonviaPUT Time elapsed: 0.001 s <<< FAILURE!
org.opentest4j.AssertionFailedError
at com.example.prototype.proxy.RequestAcceptTest.assertAccept(RequestAcceptTest.java:73)
at com.example.prototype.proxy.RequestAcceptTest.lambda$testAllMimeTypes$0(RequestAcceptTest.java:64)
[ERROR] testAcceptApplicationJsonviaPOST Time elapsed: 0.001 s <<< FAILURE!
org.opentest4j.AssertionFailedError
at com.example.prototype.proxy.RequestAcceptTest.assertAccept(RequestAcceptTest.java:73)
at com.example.prototype.proxy.RequestAcceptTest.lambda$testAllMimeTypes$0(RequestAcceptTest.java:64)
Instead it is array indexed.
[ERROR] Tests run: 6, Failures: 6, Errors: 0, Skipped: 0, Time elapsed: 1,578.898 s <<< FAILURE! - in com.example.prototype.proxy.RequestAcceptTest
[ERROR] testAllMimeTypes[1] Time elapsed: 0.013 s <<< FAILURE!
org.opentest4j.AssertionFailedError
at com.example.prototype.proxy.RequestAcceptTest.assertAccept(RequestAcceptTest.java:73)
at com.example.prototype.proxy.RequestAcceptTest.lambda$testAllMimeTypes$0(RequestAcceptTest.java:64)
[ERROR] testAllMimeTypes[2] Time elapsed: 0.001 s <<< FAILURE!
org.opentest4j.AssertionFailedError
at com.example.prototype.proxy.RequestAcceptTest.assertAccept(RequestAcceptTest.java:73)
at com.example.prototype.proxy.RequestAcceptTest.lambda$testAllMimeTypes$0(RequestAcceptTest.java:64)
[ERROR] testAllMimeTypes[3] Time elapsed: 0.001 s <<< FAILURE!
org.opentest4j.AssertionFailedError
at com.example.prototype.proxy.RequestAcceptTest.assertAccept(RequestAcceptTest.java:73)
at com.example.prototype.proxy.RequestAcceptTest.lambda$testAllMimeTypes$0(RequestAcceptTest.java:64)
As well, the failure summary just shows the lambda names and does not contain any reference to displayName
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] RequestAcceptTest.lambda$testAllMimeTypes$0:64->assertAccept:73
[ERROR] RequestAcceptTest.lambda$testAllMimeTypes$0:64->assertAccept:73
[ERROR] RequestAcceptTest.lambda$testAllMimeTypes$0:64->assertAccept:73
In reality, I don't have 6 or 10 test, but 10,000. I don't care how, but I do need some information I control to show up in the test output.
If I'm unable to communicate to the casual observer what the test was, then the feature is unfortunately not usable and I'll probably have to go back to bytecode generating test methods.
I also do not know if this is a JUnit question or a Maven-Surefire-Plugin question.
Maven took back surefire integration but didnt integrate with displayname yet :(. https://github.com/junit-team/junit5/issues/990
Romain
If you configure maven-surefire-plugin, then the XML report will contain testcase name as "A() - B", where:
A is method name with annotation #TestFactory
B is is displayName from DynamicTest
pom.xml/build/plugins:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
<configuration>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
</configuration>
</plugin>
https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html#Surefire_Extensions_and_Reports_Configuration_for_.40DisplayName
https://issues.apache.org/jira/browse/SUREFIRE-1546

Resources