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

我有 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 构建期间独立运行?


大话西游666
浏览 172回答 1
1回答

BIG阳

使用 maven-surefire-plugin 来包含你的测试套件,&nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-surefire-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <includes>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <include>**/RabbitMQIntegrationTestSuite.java</include>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </includes>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java