maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r809740 - in /maven/surefire/trunk: surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/ surefire-integration-tests/src/test/resources/junit4-for...
Date Mon, 31 Aug 2009 20:48:59 GMT
Author: jdcasey
Date: Mon Aug 31 20:48:58 2009
New Revision: 809740

URL: http://svn.apache.org/viewvc?rev=809740&view=rev
Log:
[SUREFIRE-571] Put off instantiation of the Runner instance for a JUnit4TestSet instance until
that test set is executed, to prevent static initialization of classes not currently being
executed.

Added:
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestJUnit4ForkAlwaysStaticInitPollution.java
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/pom.xml
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/App2Test.java
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/AppTest.java
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/org/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/org/apache/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/org/apache/maven/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/org/apache/maven/surefire/
Modified:
    maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestJUnit4ForkAlwaysStaticInitPollution.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestJUnit4ForkAlwaysStaticInitPollution.java?rev=809740&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestJUnit4ForkAlwaysStaticInitPollution.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestJUnit4ForkAlwaysStaticInitPollution.java
Mon Aug 31 20:48:58 2009
@@ -0,0 +1,30 @@
+package org.apache.maven.surefire.its;
+
+
+import java.io.File;
+
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * Test JUnit 4 tests marked with "Ignore" attribute 
+ * 
+ * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
+ * 
+ */
+public class TestJUnit4ForkAlwaysStaticInitPollution
+    extends AbstractSurefireIT
+{
+    public void testJunit4Ignore ()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/junit4-forkAlways-staticInit"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        this.executeGoal( verifier, "test" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+        
+        HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, testDir );        
+    }
+}

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestJUnit4ForkAlwaysStaticInitPollution.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/pom.xml?rev=809740&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/pom.xml
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/pom.xml
Mon Aug 31 20:48:58 2009
@@ -0,0 +1,41 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.surefire.test</groupId>
+  <artifactId>junit4-forkAlways-staticInit</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  
+  <name>JUnit4 ForkAlways StaticInit Pollution</name>
+  <description>
+    Test that static initializers on classes other than the one being executed in the current
test-set will not be run, and cannot pollute the environment.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.5</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire.version}</version>
+        <configuration>
+          <forkMode>always</forkMode>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/App2Test.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/App2Test.java?rev=809740&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/App2Test.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/App2Test.java
Mon Aug 31 20:48:58 2009
@@ -0,0 +1,31 @@
+package junit4;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for simple App.
+ */
+public class App2Test 
+    extends TestCase
+{
+    
+    static
+    {
+        System.out.println( "Loading " + App2Test.class.getName() );
+        
+        Properties p = System.getProperties();
+        p.setProperty( "Foo", "Bar2" );
+        System.setProperties( p );
+    }
+    
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        System.out.println( "Expecting: Bar2\nGot: " + System.getProperty( "Foo" ) );
+        assertEquals( "Expecting: Bar2\nGot: " + System.getProperty( "Foo" ), "Bar2", System.getProperty(
"Foo" ) );
+    }
+}

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/App2Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/AppTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/AppTest.java?rev=809740&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/AppTest.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/AppTest.java
Mon Aug 31 20:48:58 2009
@@ -0,0 +1,31 @@
+package junit4;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest 
+    extends TestCase
+{
+    
+    static
+    {
+        System.out.println( "Loading " + AppTest.class.getName() );
+        
+        Properties p = System.getProperties();
+        p.setProperty( "Foo", "Bar" );
+        System.setProperties( p );
+    }
+    
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        System.out.println( "Expecting: Bar\nGot: " + System.getProperty( "Foo" ) );
+        assertEquals( "Expecting: Bar\nGot: " + System.getProperty( "Foo" ), "Bar", System.getProperty(
"Foo" ) );
+    }
+}

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-forkAlways-staticInit/src/test/java/junit4/AppTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java?rev=809740&r1=809739&r2=809740&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java
Mon Aug 31 20:48:58 2009
@@ -30,9 +30,6 @@
 public class JUnit4TestSet
     extends AbstractTestSet
 {
-    // Member Variables
-    private Runner junitTestRunner;
-
     /**
      * Constructor.
      *
@@ -41,8 +38,6 @@
     protected JUnit4TestSet( Class testClass )
     {
         super( testClass );
-
-        junitTestRunner = Request.aClass( testClass ).getRunner();
     }
 
     /**
@@ -53,6 +48,8 @@
     public void execute( ReporterManager reportManager, ClassLoader loader )
         throws TestSetFailedException
     {
+        Runner junitTestRunner = Request.aClass( getTestClass() ).getRunner();
+        
         RunNotifier fNotifier = new RunNotifier();
         RunListener listener = new JUnit4TestSetReporter( this, reportManager );
         fNotifier.addListener( listener );



Mime
View raw message