Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Incomplete
-
Affects Version/s: None
-
Fix Version/s: None
-
Labels:None
-
Environment:Windows XP and RedHat 9.0
-
Number of attachments :
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>$
<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
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>
{maven.test.dest}<junit printsummary="yes" haltonfailure="no" failureProperty="maven.test.failure" fork="false">
<classpath>
<pathelement location="$
"/>
{maven.build.dest}<pathelement location="$
"/>
{maven.test.searchdir}<path refid="maven.dependency.classpath"/>
</classpath>
<batchtest>
<fileset dir="$
">
<include name="**/Test.java"/>
</fileset>
</batchtest>
</junit>
</goal>