groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject [2/2] groovy git commit: redirect TestNg test output to target directory
Date Tue, 04 Jul 2017 04:03:44 GMT
redirect TestNg test output to target directory


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/44b89dab
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/44b89dab
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/44b89dab

Branch: refs/heads/master
Commit: 44b89dab6be7669c5e5682ed9eed7b800dcc4710
Parents: fdd0b4b
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Mon Jul 3 19:49:14 2017 -0700
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Mon Jul 3 19:49:14 2017 -0700

----------------------------------------------------------------------
 .../org/apache/groovy/plugin/testng/TestNgRunner.java | 14 ++++++++++++++
 .../groovy/plugin/testng/TestNgRunnerTest.groovy      | 12 ++++++++++++
 2 files changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/44b89dab/subprojects/groovy-testng/src/main/java/org/apache/groovy/plugin/testng/TestNgRunner.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-testng/src/main/java/org/apache/groovy/plugin/testng/TestNgRunner.java
b/subprojects/groovy-testng/src/main/java/org/apache/groovy/plugin/testng/TestNgRunner.java
index e9f0b94..53b1e9d 100644
--- a/subprojects/groovy-testng/src/main/java/org/apache/groovy/plugin/testng/TestNgRunner.java
+++ b/subprojects/groovy-testng/src/main/java/org/apache/groovy/plugin/testng/TestNgRunner.java
@@ -31,6 +31,17 @@ import java.lang.reflect.Method;
  */
 public class TestNgRunner implements GroovyRunner {
 
+    /** Path to the desired test-output directory, else null */
+    private static final String OUTPUT_DIRECTORY = getTestOutputDirectory();
+
+    private static String getTestOutputDirectory() {
+        try {
+            return System.getProperty("groovy.plugin.testng.output");
+        } catch (SecurityException ignore) {
+            return null;
+        }
+    }
+
     /**
      * Utility method to check via reflection if the parsed class appears to be a TestNG
      * test, i.e. checks whether it appears to be using the relevant TestNG annotations.
@@ -77,6 +88,9 @@ public class TestNgRunner implements GroovyRunner {
             Class<?> listenerClass = loader.loadClass("org.testng.TestListenerAdapter");
             Object listener = InvokerHelper.invokeConstructorOf(listenerClass, new Object[]{});
             InvokerHelper.invokeMethod(testng, "addListener", new Object[]{listener});
+            if (OUTPUT_DIRECTORY != null) {
+                InvokerHelper.invokeMethod(testng, "setOutputDirectory", new Object[]{OUTPUT_DIRECTORY});
+            }
             return InvokerHelper.invokeMethod(testng, "run", new Object[]{});
         } catch (ClassNotFoundException e) {
             throw new GroovyRuntimeException("Error running TestNG test.", e);

http://git-wip-us.apache.org/repos/asf/groovy/blob/44b89dab/subprojects/groovy-testng/src/test/groovy/org/apache/groovy/plugin/testng/TestNgRunnerTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-testng/src/test/groovy/org/apache/groovy/plugin/testng/TestNgRunnerTest.groovy
b/subprojects/groovy-testng/src/test/groovy/org/apache/groovy/plugin/testng/TestNgRunnerTest.groovy
index 0b23015..cda81f4 100644
--- a/subprojects/groovy-testng/src/test/groovy/org/apache/groovy/plugin/testng/TestNgRunnerTest.groovy
+++ b/subprojects/groovy-testng/src/test/groovy/org/apache/groovy/plugin/testng/TestNgRunnerTest.groovy
@@ -20,6 +20,18 @@ package org.apache.groovy.plugin.testng
 
 class TestNgRunnerTest extends GroovyShellTestCase {
 
+    @Override
+    void setUp() {
+        super.setUp()
+        System.setProperty('groovy.plugin.testng.output', 'target/testng-output')
+    }
+
+    @Override
+    void tearDown() {
+        super.tearDown()
+        System.clearProperty('groovy.plugin.testng.output')
+    }
+
     void testRunWithTestNg() {
         String test = '''
             class F {


Mime
View raw message