add to pom
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>false</skipTests> <excludes> <exclude>**/*IntegrationTest.java</exclude> </excludes> </configuration> <executions> <execution> <id>integration-test</id> <goals> <goal>test</goal> </goals> <phase>integration-test</phase> <configuration> <excludes> <exclude>none</exclude> </excludes> <includes> <include>**/*IntegrationTest.java</include> </includes> </configuration> </execution> </executions> </plugin>
create class
import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class IntegrationTest { @org.junit.Before public void setUp() throws Exception { System.out.println("setUp"); } @After public void tearDown() throws Exception { System.out.println("tearDown "); } @Test public void testfirst() throws Exception { System.out.println("testfirst"); } @Test public void testsecond() throws Exception { System.out.println("testsecond"); // Assert.fail(); } }
run mvn clean verify package
[INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ GreetTime --- [INFO] Building jar: C:\Users\\IdeaProjects\GreetJar\target\GreetTime-1.0.jar [INFO] [INFO] --- maven-assembly-plugin:2.2-beta-5:single (default) @ GreetTime --- [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] Building jar: C:\Users\IdeaProjects\GreetJar\target\GreetTime-1.0-jar-with-dependencies.jar [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] [INFO] --- maven-surefire-plugin:2.10:test (integration-test) @ GreetTime --- [INFO] Surefire report directory: C:\Users\\IdeaProjects\GreetJar\target\surefire-reports ------------------------------------------------------- TESTS ------------------------------------------------------- Running IntegrationTest setUp testsecond tearDown setUp testfirst tearDown Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.11 sec Results : Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ GreetTime --- [debug] execute contextualize [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, ie build is platform dependent! [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ GreetTime --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ GreetTime --- [debug] execute contextualize [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, ie build is platform dependent! [INFO] skip non existing resourceDirectory IdeaProjects\GreetJar\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ GreetTime --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ GreetTime --- [INFO] Skipping execution of surefire because it has already been run for this configuration [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ GreetTime --- [INFO] [INFO] --- maven-assembly-plugin:2.2-beta-5:single (default) @ GreetTime --- [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] Building jar: \IdeaProjects\GreetJar\target\GreetTime-1.0-jar-with-dependencies.jar [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [WARNING] Artifact Time:GreetTime:jar:jar-with-dependencies:1.0 already attached to project, ignoring duplicate [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.373s [INFO] Finished at: Sat Sep 17 13:40:45 MSK 2016 [INFO] Final Memory: 21M/265M [INFO] ------------------------------------------------------------------------ Process finished with exit code 0