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

maven-bloop: JUnit tests don't work out of the box #28

Open
nigredo-tori opened this issue Oct 10, 2021 · 1 comment
Open

maven-bloop: JUnit tests don't work out of the box #28

nigredo-tori opened this issue Oct 10, 2021 · 1 comment

Comments

@nigredo-tori
Copy link

nigredo-tori commented Oct 10, 2021

Symptoms

After importing a Maven project to Metals, it doesn't show lenses for JUnit test classes, as well as for ZIO specs which piggyback on JUnit machinery as described here.

Reproduction

(This example focuses on running tests via Bloop CLI, but the root reason is the same, and fixing one leads to fixing the other)

Consider this Maven project: example.zip. It includes a single
failing test that requires JUnit to run. Maven understands this:

$ mvn test
...
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
...

After importing the project to Bloop as described here, we can attempt to run the tests, but Bloop doesn't recognize them:

$ bloop test my-artifact-test
...
[E] Missing configured test frameworks in my-artifact-test
===============================================
Total duration: 0ms
No test suites were run.
===============================================

The missing piece seems to be the JUnit-SBT bridge (com.novocode:junit-interface:0.11) - after adding the corresponding dependency (by uncommenting it in pom.xml) and reimporting the project, we get the desired result:

$ bloop test my-artifact-test
...
===============================================
Total duration: 9ms
1 failed

Failed:
- BarTest:
  * BarTest.evaluatesExpression - java.lang.AssertionError: expected:<4> but was:<5>
===============================================

Workaround

Add this dependency to your pom.xml:

    <dependency>
      <groupId>com.novocode</groupId>
      <artifactId>junit-interface</artifactId>
      <version>0.11</version>
      <scope>test</scope>
    </dependency>

Note that this is inconvenient, since it requires modifying the Maven project and preserving the change for later imports, either by pushing it upstream with the corresponding review process, or by inventing some way to "keep it alive" locally for future imports. I'm not aware of a palatable way to add a dependency to an existing Maven project without modiying pom.xml (like a local .sbt file in SBT).

@tgodzik
Copy link
Contributor

tgodzik commented Oct 20, 2021

Thanks for reporting! Bloop uses the same mechanism for tests as sbt and without junit-interface class it's unable to use the junit test framework. We might want to add the interface if it's missing in the project, though I am not sure if it's the perfect solution 🤔

This would need to be done around https://github.com/scalacenter/bloop/blob/master/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala#L185

@ckipp01 ckipp01 transferred this issue from scalacenter/bloop Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants