Skip to content

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

@nigredo-tori

Description

@nigredo-tori

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions