eclipse-vertx / vertx-junit5

Testing Vert.x applications with JUnit 5
Apache License 2.0
42 stars 30 forks source link

@BeforeAll not working properly with VertxExtension class #123

Closed Xing97 closed 1 year ago

Xing97 commented 1 year ago

Version

4.3.4

Context

The annotation @BeforeAll is not working properly. If we have a superclass that has a @BeforeAll asynchronous method and a subclass with a @BeforeAll asynchronous method as well (different name), the method of the subclass does not wait for the superclass method to finish.

Do you have a reproducer?

We have this superclass:

public abstract class AbstractTest {

  @BeforeAll
  static void superBeforeAll(Vertx vertx, VertxTestContext testContext) {
    vertx.deployVerticle(new OtherVerticle(), testContext.succeeding(id -> {
      System.out.println("Superclass completed");
      testContext.completeNow();
    }));
  }
}

And this subclass:

@ExtendWith(VertxExtension.class)
public class TestMainVerticle extends AbstractTest {

  @BeforeAll
  static void deploy(Vertx vertx, VertxTestContext testContext) {
    vertx.deployVerticle(new MainVerticle(), testContext.succeeding(id -> {
      System.out.println("Subclass completed");
      testContext.completeNow();
    }));
  }

  @Test
  void test(Vertx vertx, VertxTestContext testContext) {
    testContext.completeNow();
  }
}

Verticle classes:

public class MainVerticle extends AbstractVerticle {

  @Override
  public void start(Promise<Void> startPromise) throws Exception {
    startPromise.complete();
  }
}

public class OtherVerticle extends AbstractVerticle {

  @Override
  public void start(Promise<Void> startPromise) throws Exception {
    Thread.sleep(1000); // Delay start
    startPromise.complete();
  }
}

If we execute the subclass test, we get this output:

Subclass completed
Superclass completed

The subclass BeforeAll is completed first without waiting for the superclass method.

matter-it-does commented 1 year ago

Yes! I thought I was the only one or had some issue in my code

Same happens in nested classes (i.e. without extending any class)

matter-it-does commented 1 year ago

@tsegismont pls look