使用带有junit的vertx TestSuite

时间:2017-08-18 19:48:25

标签: java gradle junit vert.x

我一直关注vertx junit integration example,但我不明白如何从junit @test方法或junit @ Suite.SuiteClasses运行TestSuite?

@RunWith(VertxUnitRunner.class)
public class RunOnContextJUnitTestSuite {

  @Rule
  public RunTestOnContext rule = new RunTestOnContext();

  @Test
  public void testSomething(TestContext context) {
    // Use the underlying vertx instance
    Vertx vertx = rule.vertx();
  }
}

我想从Gradle运行vertx TestSuite测试,但它只与junit集成,我不知道如何在junit中运行TestSuite。

2 个答案:

答案 0 :(得分:0)

你有很多选择 1.从IDE运行各个测试(IntelliJ和eclipse都工作) 2.使用maven运行测试

http://github.com/vert-x3/vertx-examples有很多例子可以向您展示您需要做什么

答案 1 :(得分:0)

我正在使用:

testCompile group: 'io.vertx', name: 'vertx-junit5', version: "$vertx_version"
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.1.0'

我做了以下事情:

@ExtendWith(VertxExtension::class) abstract class BaseTest {

    companion object {
        lateinit var injector : Injector

        init {
            // things that may need to be setup before companion class member variables are instantiated
        }

        @BeforeAll
        @JvmStatic
        fun deploy_verticle(vertx: Vertx, testContext: VertxTestContext) {

            Json.mapper.registerModule(KotlinModule())
            val rxVertx = io.vertx.reactivex.core.Vertx(vertx)
            injector = Guice.createInjector(TestModule(rxVertx))
            val main = injector.getInstance(MainVerticle::class.java)
            vertx.deployVerticle(main, testContext.succeeding { id -> testContext.completeNow() })

        }

    } }

然后我像这样扩展baseTest类:

class SomeTestClass: BaseTest() {
    @AfterEach
    fun `Check that the verticle is still there`(vertx: Vertx) {
        Assertions.assertTrue(!vertx.deploymentIDs().isEmpty())
    }

    @Test
    fun someTest(vertx: Vertx, testContext: VertxTestContext){

     ...
    }}