6

maven 故障安全插件需要能够区分单元测试和集成测试。似乎在使用 JUnit 时,一种分离测试的方法是使用 JUnit @Categories 注释。这篇博文展示了如何使用 junit http://www.agile-engineering.net/2012/04/unit-and-integration-tests-with-maven.html

@Category(IntegrationTest.class)
public class ExampleIntegrationTest{

 @Test
 public void longRunningServiceTest() throws Exception {

 }
}

如何使用 TestNG 和 Maven 故障安全插件完成同样的事情。我想在测试类上使用注释将它们标记为集成测试。

4

3 回答 3

2

这可以添加到测试中。

@IfProfileValue(name="test-profile", value="IntegrationTest")
public class PendingChangesITCase extends AbstractControllerIntegrationTest {
    ...
}

要选择要执行的测试,只需将值添加到配置文件以执行集成测试。

<properties>
    <test-profile>IntegrationTest</test-profile>
</properties>

如果选择的 Maven 配置文件没有属性值,它将不会执行集成测试。

于 2013-11-26T15:19:19.800 回答
1

我们使用 maven-surefire-plugin 进行单元测试,使用 maven-failsafe-plugin 进行集成测试。它们都与声纳很好地集成在一起。

于 2013-11-26T16:01:37.507 回答
0

看起来我参加这个聚会迟到了,但对于未来的谷歌人来说,我通过以下方式让它工作:

使用您选择的组名注释相关的测试类:

@Test(groups='my-integration-tests')
public class ExampleIntegrationTest {
  @Test
  public void someTest() throws Exception {

 }
}

告诉surefire插件(运行正常的单元测试阶段)忽略您的集成测试:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <excludedGroups>my-integration-tests</excludedGroups>
  </configuration>
</plugin>

并告诉故障安全插件(运行集成测试)只关心你的组。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.20</version>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <includes>**/*.java</includes>
    <groups>my-integration-tests</groups>
  </configuration>
</plugin>
于 2017-07-26T17:01:56.920 回答