在 Maven 中如何 运行 将 JUnit 测试用例作为测试套件的一部分而不是单独使用?

In Maven how to run a JUnit test case as part of a test suite and not alone?

我有 3 个 JUnit 测试用例 运行 作为测试套件的一部分。测试套件启动和停止这些测试使用的嵌入式 Rabbit MQ 服务器 类。

@RunWith(Suite.class)
@Suite.SuiteClasses({
    TestQueueGateway.class, 
    TestRabbitMQConnectionFactory.class, 
    TestRabbitMQQueue.class
})
public class RabbitMQIntegrationTestSuite {
@BeforeClass
public static void setupRabbitMQServer() {
    //Start embedded server
}

@AfterClass
public static void _tearDownAfterClass() {
    //stop server
}
}

我可以在 Eclipse 中 运行 这个测试套件并查看测试用例是否正确。但是,当我 运行 Maven 构建时,3 个测试 类 独立 运行 并且失败了,因为它们没有所需的服务器设置。

请告诉我如何使 3 测试 类 运行 仅作为测试套件的一部分,而不是 运行 在 Maven 构建期间独立进行?

使用 maven-surefire-plugin 包含您的测试套件,

      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <includes>
                    <include>**/RabbitMQIntegrationTestSuite.java</include>
                </includes>
            </configuration>
        </plugin>