jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
Maven 1.x Test Plugin
  • Maven 1.x Test Plugin
  • MPTEST-44

JUnit fork is not working

  • Log In
  • Views
    • XML
    • Word
    • Printable

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

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Zip Archive
    test-fork.zip
    11/Oct/04 3:14 PM
    5 kB
    Thomas Van de Velde
    1. File
      MAVEN-TEST/.classpath 0.4 kB
    2. File
      MAVEN-TEST/.project 0.4 kB
    3. File
      MAVEN-TEST/bin/BaseClass.class 0.5 kB
    4. File
      MAVEN-TEST/bin/Class1Test.class 0.4 kB
    5. File
      MAVEN-TEST/bin/Class2Test.class 0.4 kB
    6. File
      MAVEN-TEST/bin/Class3Test.class 0.4 kB
    7. XML File
      MAVEN-TEST/build.xml 0.3 kB
    8. XML File
      MAVEN-TEST/project.xml 0.6 kB
    9. Java Source File
      MAVEN-TEST/src/BaseClass.java 0.5 kB
    10. Java Source File
      MAVEN-TEST/src/Class1Test.java 0.5 kB
    11. Java Source File
      MAVEN-TEST/src/Class2Test.java 0.5 kB
    12. Java Source File
      MAVEN-TEST/src/Class3Test.java 0.5 kB
    Download Zip
    Show
    Zip Archive
    test-fork.zip
    11/Oct/04 3:14 PM
    5 kB
    Thomas Van de Velde

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Thomas Van de Velde added a comment - 05/Jan/05 8:14 AM

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 - 05/Jan/05 8:14 AM 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
Permalink
Brett Porter added a comment - 07/Jan/05 6:42 PM

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 - 07/Jan/05 6:42 PM 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
Vote (0)
Watch (0)

Dates

  • Created:
    11/Oct/04 3:11 PM
    Updated:
    07/Jan/05 6:42 PM
    Resolved:
    07/Jan/05 6:42 PM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.