简体   繁体   English

Maven 故障安全插件总是跳过集成测试

[英]Maven Failsafe Plugin is always skipping integration tests

I am attempting to configure my Maven project to have unit tests and integration tests.我正在尝试配置我的 Maven 项目以进行单元测试和集成测试。 The unit tests are already working fine using the Maven Surefire plugin and are named according to the pattern *Test.java .单元测试已经使用 Maven Surefire 插件运行良好,并根据*Test.java模式命名。

After adding the Failsafe plugin, like so:添加故障安全插件后,如下所示:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18.1</version>
            <dependencies>
              <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit47</artifactId>
                <version>2.18.1</version>
              </dependency>
            </dependencies>
            <configuration>
                <includes>
                    <include>**/*IT.java</include>
                </includes>
            </configuration>
            <executions>
              <execution>
                <id>integration-test</id>
                <goals>
                  <goal>integration-test</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

I added an integration test named SomeTestIT.java .我添加了一个名为SomeTestIT.java的集成测试。 However, when I run:但是,当我运行时:

mvn failsafe:integration-test

I get the following:我得到以下信息:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MyApp 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (default-cli) @ MyApp ---
[INFO] Tests are skipped.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.368 s
[INFO] Finished at: 2015-03-04T14:43:50-06:00
[INFO] Final Memory: 11M/219M
[INFO] ------------------------------------------------------------------------

My test class (buried a few package levels deep beneath the test hierarchy) looks something like:我的测试类(在测试层次结构下深埋了几个包级别)看起来像:

package com.example.my.package;

import org.junit.Test;
import org.junit.Assert;
import com.example.my.package.SomeService;

import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.beans.factory.annotation.Autowired;

@RunWith(SpringJUnit4ClassRunner.class)
public class SomeTestIT
{
    @Autowired
    private SomeService target;

    @Test
    public void testTest()
    {
        Assert.assertTrue(false);
    }

    @Test
    public void basicListTest()
    {
        Assert.assertNotNull(target);
    }
}

Where the tests are stubs to make sure that I have the Maven integration working.测试是存根的地方,以确保我有 Maven 集成工作。

I have ensured that:我已确保:

  • My POM includes a direct, test scoped dependency on JUnit.我的 POM 包括对 JUnit 的直接、测试范围的依赖。
  • I have tried the plugin configuration both with and without an explicit test runner dependency.我已经尝试了带有和不带有显式测试运行器依赖项的插件配置。
  • I have tried the configuration above both with and without an explicit include pattern (on the assumption that my class ought to have been picked up by the defaults).我已经在使用和不使用显式包含模式的情况下尝试了上面的配置(假设我的类应该被默认值选中)。

Nonetheless, the tests never actually run.尽管如此,这些测试从未真正运行过。 Is there anything else necessary to get the integration tests running?是否还有其他必要让集成测试运行?

I finally figured out what was going on and wanted to keep anyone else from spinning their wheels like I did.我终于弄清楚发生了什么,并希望阻止其他人像我一样转动他们的轮子。 In the <properties> tag at the head of the POM, someone had added a property that read <skipITs>true</skipITs> .在 POM 开头的<properties>标记中,有人添加了一个属性,该属性显示为<skipITs>true</skipITs> There were no integration tests previously, so the property was useless.之前没有集成测试,所以这个属性没用。 It was probably cargo-culted out of some other POM without any real regard for what it is or what it does.它可能是从其他一些 POM 中从货物中培养出来的,而没有真正考虑它是什么或它做什么。

My problem was that maven failsafe plugin was already defined in some parent pom and was configured oddly.我的问题是 maven 故障安全插件已经在某些父 pom 中定义并且配置很奇怪。

In general, the best way I have found to handle this kind of issues is to first look at the effective pom:一般来说,我发现处理此类问题的最佳方法是首先查看有效的 pom:

mvn help:effective-pom

and check (1) all properties (2) the configuration of the problematic plugin并检查(1)所有属性(2)有问题的插件的配置

IntelliJ users should be sure to check their settings! IntelliJ 用户应该确保检查他们的设置!

As shown in the screenshot below, there is an option in如下面的截图所示,有一个选项

Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Runner

If checked, Maven will skip integration tests in the failsafe plugin!如果选中,Maven 将跳过故障安全插件中的集成测试! It seems to have a similar effect as skipITs in one of the other answers.它似乎与其他答案之一中的skipITs具有类似的效果。 However, because IntelliJ passes it as an argument to its Maven command, it of course does not show up in the effective POM (also mentioned in a different answer).但是,因为 IntelliJ 将它作为参数传递给它的 Maven 命令,它当然不会出现在有效的 POM 中(也在不同的答案中提到)。

跳过测试选项

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

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