我试图将我的Maven项目配置为具有单元测试和集成测试。使用Maven Surefire插件的单元测试已经可以正常运行并根据模式进行命名*Test.java
。
添加故障安全插件后,如下所示:
<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>
我添加了一个名为的集成测试SomeTestIT.java
。但是,当我运行时:
mvn failsafe:integration-test
我得到以下内容:
[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] ------------------------------------------------------------------------
我的测试类(在测试层次结构的深处埋有几个软件包级别)看起来像:
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);
}
}
测试在哪里进行存根以确保我可以进行Maven集成。
我确保:
尽管如此,测试从未真正运行过。要运行集成测试还有其他必要的条件吗?
我终于弄清楚了发生了什么,并想阻止其他人像我一样转动自己的车轮。在<properties>
POM顶部的标签中,有人添加了一个属性为<skipITs>true</skipITs>
。以前没有集成测试,因此该属性没有用。它可能是从其他一些POM中冒出来的,没有真正考虑它是什么或做什么。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句