Reputation: 47
While preparing a release on maven (release:prepare) I've commented some tests I don't want to perform, but they are executed anyway, even completely removing the @Test
annotation form the method.
NOTE: Consider that the Skip Test option is ignored during maven release
The build was performed under Eclipse wit the following environment:
- Apache Maven 3.5.4 external run-time (not the one embedded in Eclipse)
- Java JDK 1.8.0_151
- maven-compiler-plugin 3.0
- maven-release-plugin 2.5.3
- junit-jupiter-api 5.5.2
- junit-jupiter-engine 5.5.2
Usually to skip a test I comment only the annotation:
//@Test
public void testIwantToSkip() {
assertTrue(true);
}
At the moment the only way I've found to skip a test is to comment the whole method, but I expect it to be skipped only commenting the annotation, like it happened on Junit 4.
UPDATE
I've also tried to use the @Disable
annotation, unfortunately with no result. Sample:
@Test
@Disabled
public void testAuditMapper() {
....
}
POSSIBLE SOLUTION
After several tests and thanks to Kayaman hint I've figured out that under Maven build the annotations are totally ignored, only methods that start with "test
" will be executed, the others will be totally ignored, regardless of the annotations. In example:
@Test
public void someThing() {
// will NOT be executed....
}
@Disabled
public void testSomeThing() {
// will be executed....
}
DEFINITIVE SOLUTION
In the build section of my pom the surefire plugin was not specified, so the resulting pom was using the 2.12.4 version of this plugin. By adding this in the build section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
everything works as expected. Thanks @asa for hint.
Upvotes: 1
Views: 948
Reputation: 4040
If you are experiencing the issue during the release:perform goal, you will not be able to change your java class. Normally the perform goal takes the class committed in your SCM during the release:prepare phase. Your only options at this stage would be disable all the tests during the perform stage or rollback the commits from the prepare goal and use the conditional test features of Junit5 to condition their executions.
UPDATED Solution:
The maven project was using the default version of the surefire plugins (used for units tests) and not a more recent one which resolves some issues with JUnit 5.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
Note: the use of the following plugin is very handly to ensure a project use the latest version of dependencies but most importantly the latest build ones:
https://www.mojohaus.org/versions-maven-plugin/
Upvotes: 0
Reputation: 35805
Regarding your note:
For the release plugin, you need to specify all options for the inner build indirectly, by wrapping them into
-Darguments="..."
Upvotes: 0
Reputation: 130
Try using @Ignore annotation.
@Test
@Ignore("optional comment explaning the reason")
public void testIwantToSkip() {
assertTrue(true);
}
Upvotes: 1