Skip to content

[junit-platform-engine] ClassCastExceptions running Surefire while test succeeds in IntelliJ #1837

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

Closed
nickstolwijk opened this issue Dec 9, 2019 · 4 comments
Labels
🐛 bug Defect / Bug

Comments

@nickstolwijk
Copy link

Describe the bug
I have a working test with a DefaultParameterTransformer (using Jackson). When I run this test in IntelliJ it succeeds. Although when running with Surefire, the test fails.

Output with Intellij:

Mapping '1.1.0' to 'java.lang.String'.
We wants a version: 1.1.0
Mapping '1.1.0' to 'nl.blue4it.stolwijk.sandbox.cucumber5.model.Version'.
We gets a version: Version{major=1, minor=1, patch=0}

1 Scenarios (1 passed)
2 Steps (2 passed)
0m0,513s

Output with Surefire:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running Version number check
Mapping '1.1.0' to 'java.lang.Object'.
We wants a version: 1.1.0
Mapping '1.1.0' to 'java.lang.Object'.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.422 s <<< FAILURE! - in Version number check
[ERROR] User wants to use 1.1.0 as version.  Time elapsed: 0.416 s  <<< ERROR!
java.lang.ClassCastException: class java.lang.String cannot be cast to class nl.blue4it.stolwijk.sandbox.cucumber5.model.Version (java.lang.String is in module java.base of loader 'bootstrap'; nl.blue4it.stolwijk.sandbox.cucumber5.model.Version is in unna
med module of loader 'app')

To Reproduce
Steps to reproduce the behavior:

  1. Clone the repository at 'https://github.com/nickstolwijk/cucumber-platformengine-surefire-issue'
  2. Run mvn verify
  3. See the build fail.
  4. Import into IDE.
  5. Run feature
  6. See the feature succeed

Expected behavior
The feature should succeed both in Surefire as in IntelliJ.

Your Environment

  • Cucumber version 5.0.0 RC2
  • Operating System and version: Windows 10
  • IntelliJ 2019.3
  • Build tool: Maven 3.6.3
  • Java: OpenJDK 11.0.2
@nickstolwijk nickstolwijk added the 🐛 bug Defect / Bug label Dec 9, 2019
@mpkorstanje
Copy link
Contributor

Could you show me your scenario and step definitions?

@nickstolwijk
Copy link
Author

Everything is in the mentioned GitHub repository.

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Dec 9, 2019

Looks like you are you are running into: #1817

        Then("The user gets an {} version.", (Version version) -> {
            System.out.println("We gets a version: " + version);
        });

Java erases the parameter types of lambdas. So for the snippet above we use type-tools to fish that information out of the constant pool. This unfortunately type tools doesn't work on Java 12 yet.

Unless you're interested in fixing type-tools your best option is to use annotation based stepdefinitions from cucumber-java or oddly enough Kotlin.

@nickstolwijk
Copy link
Author

I'm sorry, this indeed is a duplicate. I had JDK 13 on my terminal. :-(

Duplicate: #1817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

2 participants