Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Windows XP and RedHat 9.0
    • Number of attachments :
      1

      Description

      According to the test plugin's maven.junit.fork setting, Maven should not fork unit tests by default. When executing a batch test, it does however fork test classes. I have created the exact same scenario with ant and with Maven. Ant loads my static block only once, Maven loads it with each test case. Her's my test:

      TEST CLASSES

      public class BaseClass extends TestCase {

      static

      { System.out.println("Loading"); }

      }

      public class Class1Test extends BaseClass {

      public void testNothing()

      { assertEquals(true,true); }

      }

      public class Class2Test extends BaseClass {

      public void testNothing()
      { assertEquals(true,true); }

      }

      public class Class3Test extends BaseClass {

      public void testNothing()

      { assertEquals(true,true); }

      }

      ==================================================================

      ANT

      <project default="test">
      <target name="test">
      <junit printsummary="yes" haltonfailure="no">
      <classpath>
      <pathelement path="bin"/>
      </classpath>

      <batchtest fork="no">
      <fileset dir="src">
      <include name="**/Test.java"/>
      </fileset>
      </batchtest>
      </junit>

      </target>
      </project>

      test:
      [junit] Loading
      [junit] Running Class1Test
      [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0,01 sec

      [junit] Running Class2Test
      [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec

      [junit] Running Class3Test
      [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec

      BUILD SUCCESSFUL

      ==================================================================

      MAVEN

      <project>
      <dependencies>
      <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <type>jar</type>
      <properties/>
      </dependency>
      </dependencies>
      <build>
      <sourceDirectory>$

      {basedir}/src</sourceDirectory>
      <unitTestSourceDirectory>${basedir}

      /src</unitTestSourceDirectory>
      <unitTest>
      <includes>
      <include>**/*Test.java</include>
      </includes>
      </unitTest>
      </build>
      </project>

      test:test:
      [junit] Running Class1Test
      [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0,04 sec
      Loading
      [junit] Running Class2Test
      [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0,01 sec
      Loading
      [junit] Running Class3Test
      [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0,01 sec
      BUILD SUCCESSFUL

        Activity

        Hide
        Thomas Van de Velde added a comment -

        Is anybody looking into this?

        Even changing the plugin code to the exact same thing as in the ant build file does not solve the problem. I would greatly appreciate it if somebody digs deeper into this. We are using Spring and Hibernate on a project with hunderds of test cases. We cannot use Maven for executing the tests since there's no way to cache e.g. the Hibernate session factory.

        <goal name="test:test"
        description="Test the application"
        prereqs="test:compile">

        <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/>

        <echo>Starting test execution</echo>
        <junit printsummary="yes" haltonfailure="no" failureProperty="maven.test.failure" fork="false">
        <classpath>
        <pathelement location="$

        {maven.test.dest}

        "/>
        <pathelement location="$

        {maven.build.dest}

        "/>
        <path refid="maven.dependency.classpath"/>
        </classpath>
        <batchtest>
        <fileset dir="$

        {maven.test.searchdir}

        ">
        <include name="**/Test.java"/>
        </fileset>
        </batchtest>
        </junit>
        </goal>

        Show
        Thomas Van de Velde added a comment - Is anybody looking into this? Even changing the plugin code to the exact same thing as in the ant build file does not solve the problem. I would greatly appreciate it if somebody digs deeper into this. We are using Spring and Hibernate on a project with hunderds of test cases. We cannot use Maven for executing the tests since there's no way to cache e.g. the Hibernate session factory. <goal name="test:test" description="Test the application" prereqs="test:compile"> <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/> <echo>Starting test execution</echo> <junit printsummary="yes" haltonfailure="no" failureProperty="maven.test.failure" fork="false"> <classpath> <pathelement location="$ {maven.test.dest} "/> <pathelement location="$ {maven.build.dest} "/> <path refid="maven.dependency.classpath"/> </classpath> <batchtest> <fileset dir="$ {maven.test.searchdir} "> <include name="**/ Test .java"/> </fileset> </batchtest> </junit> </goal>
        Hide
        Brett Porter added a comment -

        honestly, I can't explain why this happens (probably differences in the classloader), but can assure you that it is not forking a new JVM for each instance. Run maven -X test, and then maven -X -Dmaven.junit.fork=yes and notice the difference.

        Show
        Brett Porter added a comment - honestly, I can't explain why this happens (probably differences in the classloader), but can assure you that it is not forking a new JVM for each instance. Run maven -X test, and then maven -X -Dmaven.junit.fork=yes and notice the difference.

          People

          • Assignee:
            Unassigned
            Reporter:
            Thomas Van de Velde
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: