4

首先请原谅我可能的无知,行家的做事方式对我来说很新,如果有什么我没有在这里提到的,请告诉我,我会尽力给你你需要的信息......

所以我正在尝试使用 Maven 在 Eclipse 中构建我的 webapp,我有一个包含以下内容的测试套件

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

当我通过右键单击运行测试并作为 Junit 测试运行时,这工作正常并且所有测试都通过了。

当我将它作为 Maven 构建运行并以打包一堆测试为目标时失败???

我的maven surefire插件配置如下

    <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>

这样,它将排除运行集成测试,而只运行我的测试套件中的内容。

为什么我的测试在运行 maven build 时会失败,而在只运行测试套件时却没有???

4

1 回答 1

6

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 :)

于 2013-10-29T02:33:33.467 回答