Question

First off please excuse my possible ignorance, The maven way of doing things its quite new to me, if there is anything that I have not mentioned here please let me know and I will try to give you the information you need...

So I am trying to build my webapp in Eclipse using maven, I have a test suite with the following

@RunWith(Suite.class)
@Suite.SuiteClasses({
    // all my test classes
})

this works fine and all the tests pass when I run the test by right click and run as Junit Test.

When I run this as Maven build and with the goal of package a bunch of the tests fail???

My maven surefire plugin is configured as follows

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.16</version>
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit47</artifactId>
                <version>2.16</version>
            </dependency>
        </dependencies>
        <configuration>
            <excludes>
                <exclude>**/Test*.java</exclude>
            </excludes>
            <includes>
                <include>**/DynamoUnitTestSuite.java</include>
            </includes>
        </configuration>
    </plugin>

This way it will exclude running the integration tests and only run what is in my test suite.

Why do my tests fail when running maven build but not when running just the test suite???

Était-ce utile?

La solution

OK got it sorted out...Your gonna love this.

In Eclipse I had a dependency checked out and had branched off master (we are using Git as well) as I was making changes to both projects. When I was running the JUnit runner to the tests it was passing fine because Eclipse was recognizing that it had this dependency however when I was running the maven build it was still using the older version of the dependency...

To fix this I changed the version number of the dependency and built this then manually copied it into my local maven repo and updated the main project pom file to use this...and volia it now passes all the tests on the maven build :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top