[SUREFIRE-919] TestNG plugin fails to apply 'verbose' setting from TestNG.xml


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/97092f71
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/97092f71
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/97092f71

Branch: refs/heads/master
Commit: 97092f71714dacaab7a8498142083bc5d87bd4bf
Parents: 827dd1a
Author: Tibor17 <[email protected]>
Authored: Tue Oct 13 00:48:01 2015 +0200
Committer: Tibor17 <[email protected]>
Committed: Tue Oct 13 00:48:01 2015 +0200

----------------------------------------------------------------------
 .../src/site/apt/examples/testng.apt.vm         | 35 ++++++++++++++++++--
 .../surefire/its/CheckTestNgReportTestIT.java   | 28 ++++++++++++++++
 .../src/test/resources/testng-simple/pom.xml    |  7 ++++
 .../maven/surefire/testng/TestNGExecutor.java   | 29 ++++++++++++----
 4 files changed, 90 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/97092f71/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm
----------------------------------------------------------------------
diff --git a/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm 
b/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm
index 14d3f62..11bf3be 100644
--- a/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm
+++ b/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm
@@ -38,7 +38,7 @@ Using TestNG
     <dependency>
       <groupId>org.testng</groupId>
       <artifactId>testng</artifactId>
-      <version>6.8.8</version>
+      <version>6.9.8</version>
       <scope>test</scope>
     </dependency>
   [...]
@@ -171,7 +171,7 @@ Using TestNG
   This is particularly useful for slow tests that can have high concurrency, 
or to quickly and roughly assess the independence
   and thread safety of your tests and code.
   
-  TestNG 5.10 or higher allows you to run methods in parallel test using data 
provider.
+  TestNG 5.10 and plugin version 2.19 or higher allows you to run methods in 
parallel test using data provider.
   
 +---+
 </plugins>
@@ -197,7 +197,7 @@ Using TestNG
 </plugins>
 +---+
   
-  TestNG 6.9.8 (JRE 1.7) or higher allows you to run suites in parallel.
+  TestNG 6.9.8 (JRE 1.7) and plugin version 2.19 or higher allows you to run 
suites in parallel.
   
 +---+
 </plugins>
@@ -278,6 +278,35 @@ Using TestNG
   <<<src/test/java>>>. You can filter test artifacts by the parameter 
<<<dependenciesToScan>>> to load its classes
   in current ClassLoader of surefire-testng provider.
 
+* The level of verbosity
+
+  Since the plugin version 2.19 or higher the verbosity level can be 
configured in provider property
+  <<<surefire.testng.verbose>>>. The verbosity level is between 0 and 10 where 
10 is the most detailed.
+  You can specify -1 and this will put TestNG in debug mode (no longer slicing 
off stack traces and all).
+  The default level is 0.
+  
++---+
+</plugins>
+    [...]
+      <plugin>
+        <groupId>${project.groupId}</groupId>
+        <artifactId>${project.artifactId}</artifactId>
+        <version>${project.version}</version>
+        <configuration>
+          [...]
+          <properties>
+            <property>
+              <name>surefire.testng.verbose</name>
+              <value>10</value>
+            </property>
+          </properties>
+          [...]
+        </configuration>
+      </plugin>
+    [...]
+</plugins>
++---+
+
 * Running TestNG and JUnit Tests
 
   TestNG 6.5.1 and higher provides support to run TestNG and JUnit 4.x in 
current Maven project. All you need

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/97092f71/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java
----------------------------------------------------------------------
diff --git 
a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java
 
b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java
index ff6ee58..1bad84b 100644
--- 
a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java
+++ 
b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java
@@ -23,6 +23,9 @@ import org.apache.maven.surefire.its.fixture.OutputValidator;
 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+
 /**
  * Test surefire-report on TestNG test
  *
@@ -39,4 +42,29 @@ public class CheckTestNgReportTestIT
             unpack( "/testng-simple" 
).addSurefireReportGoal().executeCurrentGoals().verifyErrorFree( 3 );
         outputValidator.getSiteFile( "surefire-report.html" 
).assertFileExists();
     }
+
+    @Test
+    public void shouldNotBeVerbose()
+        throws Exception
+    {
+        unpack( "/testng-simple" )
+            .sysProp( "testNgVersion", "5.10" )
+            .sysProp( "testNgClassifier", "jdk15" )
+            .executeTest()
+            .verifyErrorFreeLog()
+            .assertThatLogLine( containsString( "[Parser] Running:" ), is( 0 ) 
);
+    }
+
+    @Test
+    public void shouldBeVerbose()
+        throws Exception
+    {
+        unpack( "/testng-simple" )
+            .sysProp( "testNgVersion", "5.10" )
+            .sysProp( "testNgClassifier", "jdk15" )
+            .sysProp( "surefire.testng.verbose", "10" )
+            .executeTest()
+            .verifyErrorFreeLog()
+            .assertThatLogLine( containsString( "[Parser] Running:" ), is( 1 ) 
);
+    }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/97092f71/surefire-integration-tests/src/test/resources/testng-simple/pom.xml
----------------------------------------------------------------------
diff --git 
a/surefire-integration-tests/src/test/resources/testng-simple/pom.xml 
b/surefire-integration-tests/src/test/resources/testng-simple/pom.xml
index d85d82f..fffad18 100644
--- a/surefire-integration-tests/src/test/resources/testng-simple/pom.xml
+++ b/surefire-integration-tests/src/test/resources/testng-simple/pom.xml
@@ -74,6 +74,7 @@
 
   <properties>
      <testNgVersion>5.7</testNgVersion>
+    <surefire.testng.verbose>0</surefire.testng.verbose>
   </properties>
 
   <build>
@@ -93,6 +94,12 @@
         <version>${surefire.version}</version>
         <configuration>
           <runOrder>reversealphabetical</runOrder>
+          <properties>
+            <property>
+              <name>surefire.testng.verbose</name>
+              <value>${surefire.testng.verbose}</value>
+            </property>
+          </properties>
         </configuration>
       </plugin>
       

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/97092f71/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
----------------------------------------------------------------------
diff --git 
a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 
b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
index 5a91db0..05f7871 100644
--- 
a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
+++ 
b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
@@ -127,7 +127,8 @@ public class TestNGExecutor
 
         testng.setXmlSuites( xmlSuites );
         configurator.configure( testng, options );
-        postConfigure( testng, testSourceDirectory, reportManager, suite, 
reportsDirectory, skipAfterFailureCount );
+        postConfigure( testng, testSourceDirectory, reportManager, suite, 
reportsDirectory, skipAfterFailureCount,
+                       extractVerboseLevel( options ) );
         testng.run();
     }
 
@@ -275,7 +276,8 @@ public class TestNGExecutor
         TestNG testng = new TestNG( true );
         Configurator configurator = getConfigurator( options.get( 
"testng.configurator" ) );
         configurator.configure( testng, options );
-        postConfigure( testng, testSourceDirectory, reportManager, suite, 
reportsDirectory, skipAfterFailureCount );
+        postConfigure( testng, testSourceDirectory, reportManager, suite, 
reportsDirectory, skipAfterFailureCount,
+                       extractVerboseLevel( options ) );
         testng.setTestSuites( suiteFiles );
         testng.run();
     }
@@ -301,11 +303,11 @@ public class TestNGExecutor
     }
 
     private static void postConfigure( TestNG testNG, String sourcePath, final 
RunListener reportManager,
-                                       TestNgTestSuite suite, File 
reportsDirectory, int skipAfterFailureCount )
-        throws TestSetFailedException
+                                       TestNgTestSuite suite, File 
reportsDirectory, int skipAfterFailureCount,
+                                       int verboseLevel )
     {
-        // turn off all TestNG output
-        testNG.setVerbose( 0 );
+        // 0 (default): turn off all TestNG output
+        testNG.setVerbose( verboseLevel );
 
         TestNGReporter reporter = createTestNGReporter( reportManager, suite );
         testNG.addListener( (Object) reporter );
@@ -371,4 +373,19 @@ public class TestNGExecutor
         }
     }
 
+    private static int extractVerboseLevel( Map<String, String> options )
+        throws TestSetFailedException
+    {
+        try
+        {
+            String verbose = options.get( "surefire.testng.verbose" );
+            return verbose == null ? 0 : Integer.parseInt( verbose );
+        }
+        catch ( NumberFormatException e )
+        {
+            throw new TestSetFailedException( "Provider property 
'surefire.testng.verbose' should refer to "
+                                                  + "number -1 (debug mode), 
0, 1 .. 10 (most detailed).", e );
+        }
+    }
+
 }

Reply via email to