2

We recently had a bug caused by some code assuming that a classpath resource could be opened as if it were a regular file. This code was covered by unit tests which passed, because that assumption happens to hold both in Maven and Eclipse. But in production, that code was in a JAR in the service's WAR, and obviously didn't work.

We fixed the bug but I'm not quite satisfied because I can't see how to ensure that it doesn't happen again.

1 Answer 1

3

Unit tests are run using Surefire. This happens during mvn test and "test" occurs before packaging. But if you want to run tests after mvn package, you should use Failsafe.

Here's some very relevant documentation about configuring the classpath. By default, it will put ${project.build.outputDirectory} in the classpath, but you should be able to prevent that by setting classesDirectory to some other directory. Then you can add your own jar as either an additionalClasspathElements or perhaps a dependenciesToScan

Sign up to request clarification or add additional context in comments.

3 Comments

Failsafe still uses the ./target/classes classpath as opposed to just using the generated jar: link
A bit hacky, but I think it'll work, and I can't think of a better option.
@yshavit me either :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.