1mvn install -Dmaven.test.skip=true
2
3# or
4
5mvn install -DskipTests
6
7# If -Dmaven.test.skip=true (or simply -Dmaven.test.skip) is specified,
8# the test-jars aren't built, and any module that relies on them will
9# fail its build.
10
11# In contrast, when you use -DskipTests, Maven does not run the tests,
12# but it does compile them and build the test-jar, making it available
13# for the subsequent modules.
1private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
2private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
3private final PrintStream originalOut = System.out;
4private final PrintStream originalErr = System.err;
5
6@Before
7public void setUpStreams() {
8 System.setOut(new PrintStream(outContent));
9 System.setErr(new PrintStream(errContent));
10}
11
12@After
13public void restoreStreams() {
14 System.setOut(originalOut);
15 System.setErr(originalErr);
16}
17
18sample test cases:
19
20@Test
21public void out() {
22 System.out.print("hello");
23 assertEquals("hello", outContent.toString());
24}
25
26@Test
27public void err() {
28 System.err.print("hello again");
29 assertEquals("hello again", errContent.toString());
30}
1# Run all the unit test classes.
2$ mvn test
3
4# Run a single test class.
5$ mvn -Dtest=TestApp1 test
6
7# Run multiple test classes.
8$ mvn -Dtest=TestApp1,TestApp2 test
9
10# Run a single test method from a test class.
11$ mvn -Dtest=TestApp1#methodname test
12
13# Run all test methods that match pattern 'testHello*' from a test class.
14$ mvn -Dtest=TestApp1#testHello* test
15
16# Run all test methods match pattern 'testHello*' and 'testMagic*' from a test class.
17$ mvn -Dtest=TestApp1#testHello*+testMagic* test