简体   繁体   English

Maven构建测试失败,但JUnit跑者测试传递?

[英]Maven build with tests failing but JUnit runner tests passing?

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 所以我正在尝试使用maven在Eclipse中构建我的webapp,我有一个带有以下内容的测试套件

@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. 这工作正常,当我通过右键单击运行测试并运行为Junit测试时,所有测试都通过。

When I run this as Maven build and with the goal of package a bunch of the tests fail??? 当我运行这个Maven构建并且以包为目标时,一堆测试失败了???

My maven surefire plugin is configured as follows 我的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>

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??? 为什么我的测试在运行maven build时失败,但在运行测试套件时却没有?

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. 在Eclipse中,我检查了一个依赖项并且已经分支了master(我们也正在使用Git),因为我正在对这两个项目进行更改。 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... 当我运行JUnit运行程序到测试时,它传递正常,因为Eclipse认识到它具有这种依赖性,但是当我运行maven构建时,它仍然使用旧版本的依赖项...

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 :) 为了解决这个问题,我更改了依赖项的版本号并构建了它,然后手动将其复制到我的本地maven仓库并更新了主项目pom文件以使用它...而volia现在通过了maven构建的所有测试:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM