Closed MazurK239 closed 2 months ago
That is intentional. Most plugins can't handle parallel execution. You'll want to use the ConcurrentEventListener
.
Btw, for setup you might want to look at the @BeforeAll
and @AfterAll
hooks from Cucumber or depending on what you need, those recently added to the JUnit 5 Suite Engine.
Thank you @mpkorstanje. Works like a charm! sorry that I missed this in the documentation.
Didn't know about @BeforeAll
and @AfterAll
either, will definitely give them a try
@mpkorstanje, since there is yet no documentation regarding the use of BeforeAll/AfterAll could you, please, advise, how to correctly use it in Kotlin? As I see, internally, there is a check that this method is static, but with Kotlin it seems impossible to make this check pass
Docs are here:
https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-java#beforeall--afterall
And for Java to Kotlin interop you'll want to read:
https://kotlinlang.org/docs/java-to-kotlin-interop.html#static-methods
Many thanks!
I saw @MazurK239 's question and @mpkorstanje 's answer today, concerning the use of BeforeAll/AfterAll
with Cucumber in Kotlin, but I ran into a problem when trying to use those. See screenshots.
It appears Cucumber's method scanning in io.cucumber.java.MethodScanner::scan
sees both the original companion object method (which is not static) AND the synthesized one (due to @JvmStatic
) (which has been made static). I am using cucumber-java
7.20.1
As a result, I cannot get this to work in Kotlin...
Any thoughts?
@ejbartelds for bugs it's usually better to start a new issue.
See https://github.com/cucumber/cucumber-jvm/issues/2934 @mpkorstanje
π What did you see?
I registered a plugin that catches
TestRunStarted
andTestRunFinished
events to do some set-up / tear-down logic. This plugin extendsEventListener
and overrides methodsetEventPublisher
.When the tests are run sequentially (both via CLI and JUnit runners), the TestRunStarted handler is invoked, then tests are executed, then TestRunFinished handler is invoked, everything is fine CLI runner executed in IDEA
JUnit runner executed via Gradle
But when I run the tests in parallel, the handler of TestRunStarted gets invoked right after all tests have been executed. Even though the actual event time stored in event object is correct (see the timestamps in log on the screenshots) CLI runner executed in IDEA
JUnit runner executed via Gradle
In case of CLI runner I specified
--threads 2
in the program args, in case of JUnit runner I specifiedcucumber.execution.parallel.enabled=true
inside the junit-platform.properties file. The threads count doesn't affect anything in the latter case, it is reproduced even with one thread****β What did you expect to see?
I expected that during the parallel test execution the
TestRunStarted
handler will be executed once the event happens, before the tests are started. So that I could run some set-up logic inside it. Currently It seems to not be practicalπ¦ Which tool/library version are you using?
org.junit:junit-bom:5.11.0 io.cucumber:cucumber-bom:7.18.1
π¬ How could we reproduce it?
Minimal reproducible example forked from the cucumber-java skeleton: cucumber-java-issue-events
Run feature file via IntelliJ IDEA (CLI runner will be used) or via Gradle
π Any additional context?
No response