Mic*_*ael 6 java integration-testing automated-tests maven
我正在尝试配置我的Maven项目以进行单元测试和集成测试.单元测试使用Maven Surefire插件已经正常工作,并根据模式命名*Test.java.
添加Failsafe插件后,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
我添加了一个名为的集成测试SomeTestIT.java.但是,当我跑:
mvn failsafe:integration-test
Run Code Online (Sandbox Code Playgroud)
我得到以下内容:
[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] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
我的测试类(隐藏在测试层次结构深处的几个包级别)看起来像:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
测试是存根的,以确保我有Maven集成工作.
我确保:
尽管如此,测试从未实际运行过.还有其他必要来运行集成测试吗?
Mic*_*ael 13
我终于弄清楚发生了什么,并希望让其他人像我一样转动他们的车轮.在<properties>POM头部的标签中,有人添加了一个读取的属性<skipITs>true</skipITs>.以前没有集成测试,所以属性没用.它可能是从其他一些POM中剔除的,没有真正考虑它是什么或它做什么.
我的问题是 Maven 故障安全插件已经在某些父 pom 中定义并且配置很奇怪。
一般来说,我发现处理此类问题的最佳方法是首先查看有效的 pom:
mvn help:effective-pom
Run Code Online (Sandbox Code Playgroud)
并检查 (1) 所有属性 (2) 有问题的插件的配置