1

I would like to know if it is possible migrate this kind of rule(junit) to vertx-junit5 way. The original example is the RunOnContextTest.java from the public vertx-example repository in github. Here is the code:

@RunWith(VertxUnitRunner.class)
public class RunOnContextTest {

  /*
   * This rule wraps the junit calls in a Vert.x context, the Vert.x instance can be created by the
   * rule or provided like in this case.
   */
  @Rule
  public final RunTestOnContext rule = new RunTestOnContext(Vertx::vertx);

  private Thread thread;

  @Before
  public void before(TestContext context) {
    context.assertTrue(Context.isOnEventLoopThread());
    thread = Thread.currentThread();
  }

  @Test
  public void theTest(TestContext context) {
    context.assertTrue(Context.isOnEventLoopThread());
    context.assertEquals(thread, Thread.currentThread());
  } 
 @After
  public void after(TestContext context) {
    context.assertTrue(Context.isOnEventLoopThread());
    context.assertEquals(thread, Thread.currentThread());
  }

And the highlighted dependencies are:

 <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-unit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
mononoke83
  • 342
  • 2
  • 16
  • To make it work with JUnit Jupiter you’ll have to migrate both VertixUnitRunner and RunTestOnContext. You probably can replace them by a single extension. – johanneslink Oct 26 '20 at 12:43
  • When you have a while, could you write a simple code example doing that please?Thanks anyway. – mononoke83 Oct 26 '20 at 14:38
  • Can you provide a complete minimal example with your current JUnit 4 setup. Otherwise I'd have to stick everything together myself. – johanneslink Oct 27 '20 at 15:37
  • I've updated the code of my test class, I use maven-surefire-plugin as well in my general pom.xml, I haven't any special junit4 setup, is it enough for you or tell me what else do you need? – mononoke83 Oct 29 '20 at 07:12
  • Since I'm not a Maven user a minimum and complete pom.xml would be helpful. – johanneslink Oct 29 '20 at 11:31

1 Answers1

0

Vert.x has added support for this recently.

With Vert.x 4.2.0 you can use:

  @RegisterExtension
  public final RunTestOnContext rt = new RunTestOnContext();

reference in github -> https://github.com/vert-x3/vertx-junit5/issues/100