1 package org.apache.maven.surefire.its;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.it.VerificationException;
23 import org.apache.maven.it.Verifier;
24 import org.apache.maven.it.util.ResourceExtractor;
25 import org.apache.maven.surefire.its.misc.HelperAssertions;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.util.List;
30
31
32
33
34
35
36 public class CheckTestFailIfNoTestsForkModeIT
37 extends AbstractSurefireIntegrationTestClass
38 {
39 public void testFailIfNoTestsForkModeAlways()
40 throws Exception
41 {
42 doTest( "always", true );
43 }
44
45 public void testFailIfNoTestsForkModeNever()
46 throws Exception
47 {
48 doTest( "never", true );
49 }
50
51 public void testFailIfNoTestsForkModeOnce()
52 throws Exception
53 {
54 doTest( "once", true );
55 }
56
57 public void testDontFailIfNoTestsForkModeAlways()
58 throws Exception
59 {
60 doTest( "always", false );
61 }
62
63 public void testDontFailIfNoTestsForkModeNever()
64 throws Exception
65 {
66 doTest( "never", false );
67 }
68
69 public void testDontFailIfNoTestsForkModeOnce()
70 throws Exception
71 {
72 doTest( "once", false );
73 }
74
75 private void doTest( String forkMode, boolean failIfNoTests )
76 throws IOException, VerificationException
77 {
78 File testDir =
79 ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration-classWithNoTests" );
80
81 Verifier verifier = new Verifier( testDir.getAbsolutePath() );
82 List<String> goals = this.getInitialGoals();
83 goals.add( "test" );
84 goals.add( "-DforkMode=" + forkMode );
85 goals.add( "-DfailIfNoTests=" + failIfNoTests );
86 if ( failIfNoTests )
87 {
88 try
89 {
90 executeGoals( verifier, goals );
91 verifier.resetStreams();
92 verifier.verifyErrorFreeLog();
93 fail( "Build did not fail, but it should have" );
94 }
95 catch ( VerificationException e )
96 {
97
98 }
99 }
100 else
101 {
102 executeGoals( verifier, goals );
103 verifier.resetStreams();
104 verifier.verifyErrorFreeLog();
105 HelperAssertions.assertTestSuiteResults( 0, 0, 0, 0, testDir );
106 }
107 }
108 }