View Javadoc

1   package org.apache.maven.surefire.its;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * Test failIfNoTests with various forkModes.
33   *
34   * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
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                  // this is what we expected
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 }