[英]How to put the vertx @Rule about RunTestOnContext in the vertx-junit5 way?
我想知道是否可以將這種規則(junit)遷移到 vertx-junit5 方式。 原始示例是來自 github 中公共 vertx-example 存儲庫的 RunOnContextTest.java。 這是代碼:
@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());
}
突出顯示的依賴項是:
<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>
Vert.x 最近增加了對此的支持。
使用 Vert.x 4.2.0,您可以使用:
@RegisterExtension
public final RunTestOnContext rt = new RunTestOnContext();
github中的參考-> https://github.com/vert-x3/vertx-junit5/issues/100
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.