Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of BeforeAll/AfterAll in Kotlin-based Cucumber suite does not work as expected #2934

Open
ejbartelds opened this issue Oct 23, 2024 · 3 comments
Labels
πŸ“– documentation Improvements or additions to documentation

Comments

@ejbartelds
Copy link

ejbartelds commented Oct 23, 2024

πŸ‘“ What did you see?

@BeforeAll in a Kotlin-based Cucumber suite did not work as expected, even though placed in a companion object and annotated @JvmStatic

βœ… What did you expect to see?

I expected the @JvmStatic and @BeforeAll annotated method to be picked up by Cucumber without problems, as a before-all initializer method.

πŸ“¦ Which tool/library version are you using?

cucumber-java 7.20.1 kotlin 2.0.x

πŸ”¬ How could we reproduce it?

See screenhots: in Kotlin, write a suite or a test and have a beforeAll method. See the error appear.
Debug this and set a breakpoint in io.cucumber.java.MethodScanner::scan ; you'll see the beforeAll method is "seen" twice, once as a static final method (whish is OK) and once as a non-final method (in the companion object), which triggers the error.

image
image

πŸ“š Any additional context?

No response

@mpkorstanje
Copy link
Contributor

As a work around could you check if it works when you declare the functions at package level instead?

@ejbartelds
Copy link
Author

Ah, why didn't I think of that... A package method does indeed work, and is a viable workaround (for me at least). Thank you for the suggestion.

@mpkorstanje
Copy link
Contributor

Looks like it is also still impossible to accurately detect companion objects in Java without depending on kotlin-reflect.

So probably worth adding a note to the documentation of cucumber-java about this.

@mpkorstanje mpkorstanje added the πŸ“– documentation Improvements or additions to documentation label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
πŸ“– documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants