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  
23  import org.apache.maven.it.VerificationException;
24  import org.apache.maven.it.Verifier;
25  import org.apache.maven.it.util.ResourceExtractor;
26  import org.apache.maven.surefire.its.misc.HelperAssertions;
27  
28  import java.io.File;
29  import java.util.List;
30  
31  /**
32   * Test running a single test with -Dtest=BasicTest
33   *
34   * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
35   */
36  public class CheckSingleTestIT
37      extends AbstractSurefireIntegrationTestClass
38  {
39      public void testSingleTest()
40          throws Exception
41      {
42          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration" );
43  
44          Verifier verifier = new Verifier( testDir.getAbsolutePath() );
45          List<String> goals = this.getInitialGoals();
46          goals.add( "test" );
47          goals.add( "-Dtest=BasicTest" );
48          executeGoals( verifier, goals );
49          verifier.verifyErrorFreeLog();
50          verifier.resetStreams();
51  
52          HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, testDir );
53      }
54  
55      public void testSingleTestDotJava()
56          throws Exception
57      {
58          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration" );
59  
60          Verifier verifier = new Verifier( testDir.getAbsolutePath() );
61          List<String> goals = this.getInitialGoals();
62          goals.add( "test" );
63          goals.add( "-Dtest=BasicTest.java" );
64          executeGoals( verifier, goals );
65          verifier.verifyErrorFreeLog();
66          verifier.resetStreams();
67  
68          HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, testDir );
69      }
70  
71      public void testSingleTestNonExistent()
72          throws Exception
73      {
74          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration" );
75  
76          Verifier verifier = new Verifier( testDir.getAbsolutePath() );
77          List<String> goals = this.getInitialGoals();
78          goals.add( "test" );
79          goals.add( "-Dtest=DoesNotExist" );
80  
81          try
82          {
83              executeGoals( verifier, goals );
84              verifier.verifyErrorFreeLog();
85              fail( "Build should have failed" );
86          }
87          catch ( VerificationException e )
88          {
89              // as expected
90          }
91          finally
92          {
93              verifier.resetStreams();
94          }
95  
96          File reportsDir = new File( testDir, "target/surefire-reports" );
97          assertFalse( "Unexpected reports directory", reportsDir.exists() );
98      }
99  
100     public void testSingleTestNonExistentOverride()
101         throws Exception
102     {
103         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration" );
104 
105         Verifier verifier = new Verifier( testDir.getAbsolutePath() );
106         List<String> goals = this.getInitialGoals();
107         goals.add( "test" );
108         goals.add( "-Dtest=DoesNotExist" );
109         goals.add( "-DfailIfNoTests=false" );
110         executeGoals( verifier, goals );
111 
112         verifier.verifyErrorFreeLog();
113         verifier.resetStreams();
114 
115         File reportsDir = new File( testDir, "target/surefire-reports" );
116         assertFalse( "Unexpected reports directory", reportsDir.exists() );
117     }
118 }