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)
  • Maven Surefire
  • SUREFIRE-443

Provide option to merge test classpath into one directory

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 2.4
  • Fix Version/s: Backlog
  • Component/s: classloading
  • Labels:
    None
  • Environment:
    Maven 2.0.8
  • Complexity:
    Intermediate

Description

Please provide an option for the test classpath to be merged into one directory.

Maven sets up the class files as follows:

|-- target/test-classes
|   `-- Unit Test classes
|-- target/classes
    `-- Classes to be tested

When running unit tests, the desired outcome is for any file in the "target/test-classes" tree to override those in the "target/classes". Specifically that any file in classes is ignored and overridden by the file in test-classes for the tests to work as expected.
(In a sense a union on these two file trees in the order specified)

The problem arises when using a container such as Embedded JBoss to test which treats each directory as a separate scope for classloading.
Reading the ejb-3_0-fr-spec-persistence.pdf section "6.2.2 Persistence Unit Scope" spells it out quite clearly (a very short one page read) that if the "target/test-classes" and "target/classes" are each treated as a separate ejb-jar, then the runtime environment is not going to work due to these scoping rules.

I have an ugly hack in place as follows which has the desired effect, but it would be more preferable if instead Maven Surefire provided an option to merge the directories together and have just one directory in the test classpath.

<build>
        <plugins>
            ...
            <plugin>
                <!-- This correctly merges the test-classes and classes directories for an EE container -->
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>setupTestClasspath</id>
                        <phase>test-compile</phase>
                        <configuration>
                            <tasks>
                                <echo message="Setting up a single merged test classpath directory" />
                                <!-- move the originals -->
                                <mkdir dir="${basedir}/target/tmp" />
                                <move file="${basedir}/target/classes" todir="${basedir}/target/tmp" />
                                <move file="${basedir}/target/test-classes" todir="${basedir}/target/tmp" />
                                <!-- Merge into new directory -->
                                <copy todir="${basedir}/target/test-classes" overwrite="true">
                                    <fileset dir="${basedir}/target/tmp/test-classes" />
                                </copy>
                                <copy todir="${basedir}/target/test-classes" overwrite="false">
                                    <fileset dir="${basedir}/target/tmp/classes" />
                                </copy>
                                <mkdir dir="${basedir}/target/classes" />
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>restoreTestClasspath</id>
                        <phase>test</phase>
                        <configuration>
                            <tasks>
                                <echo message="Restoring original classes directories" />
                                <delete dir="${basedir}/target/classes" />
                                <move file="${basedir}/target/test-classes" tofile="${basedir}/target/test-classes-MERGED" />
                                <move file="${basedir}/target/tmp/classes" todir="${basedir}/target" />
                                <move file="${basedir}/target/tmp/test-classes" todir="${basedir}/target" />
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Dan Fabulich added a comment - 27/Jan/08 7:46 PM

That is a nasty hack, but at least you can hack it; I think this case is unusual and workaroundable so I'm marking it Minor. (Others may disagree by voting for this bug.)

Show
Dan Fabulich added a comment - 27/Jan/08 7:46 PM That is a nasty hack, but at least you can hack it; I think this case is unusual and workaroundable so I'm marking it Minor. (Others may disagree by voting for this bug.)
Hide
Permalink
Cory Prowse added a comment - 27/Jan/08 8:06 PM

Thanks Dan, I agree on the priority.

Thinking about it, this may break other modules such as Coberture?

Could you please edit the issue description and put the noformat tags around the XML at the end (I put <pre></pre> by mistake). It will make the XML a lot easier to read as it's indented nicely.

Show
Cory Prowse added a comment - 27/Jan/08 8:06 PM Thanks Dan, I agree on the priority. Thinking about it, this may break other modules such as Coberture? Could you please edit the issue description and put the noformat tags around the XML at the end (I put <pre></pre> by mistake). It will make the XML a lot easier to read as it's indented nicely.
Hide
Permalink
Anthony Whitford added a comment - 19/Nov/08 1:51 AM

For those of us using JPA, EJB3, and the Seam Framework, this is a pretty BIG deal. It would be great to have this feature so that we can easily use SeamTest, gain accurate coverage analysis, and overall promote the right thing: write tests!

Show
Anthony Whitford added a comment - 19/Nov/08 1:51 AM For those of us using JPA, EJB3, and the Seam Framework, this is a pretty BIG deal. It would be great to have this feature so that we can easily use SeamTest, gain accurate coverage analysis, and overall promote the right thing: write tests!
Hide
Permalink
Stephen Connolly added a comment - 10/Aug/10 6:05 AM

I am proposing that we mark this as "Will not fix" given that there is a workaround and I do not think this should be the responsibility of surefire.

Show
Stephen Connolly added a comment - 10/Aug/10 6:05 AM I am proposing that we mark this as "Will not fix" given that there is a workaround and I do not think this should be the responsibility of surefire.

People

  • Assignee:
    Unassigned
    Reporter:
    Cory Prowse
Vote (9)
Watch (6)

Dates

  • Created:
    26/Jan/08 9:36 PM
    Updated:
    10/Aug/10 6:05 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.