If JUnit test fails with Maven, but not in Eclipse

By | 17. Februar 2013

Did you know that the Java VM offers an „enable assertions“ parameter? And did you also know that the maven surefire plugin enables it as default and eclipse does not (because it’s JVM default) when running JUnit tests? Well, if your test fails when running it with maven but succeeds when launch it from eclipse, it could be that problem.

Runtime assertions like this: assert foo != null fail when the JVM is started with the -ea parameter and fail not if the parameter is missing or the -da (disable assertions) parameter is given.

Eclipse offers a solution to this: Just go to Window -> Preferences -> Java -> JUnit and enable that option:
Enable Assertions

Then you have to delete the previously created lunch configurations, because this change will not be applied to the existing ones.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.