java - 如何以 vertx-junit5 的方式放置关于 RunTestOnContext 的 vertx @Rule?
问题描述
我想知道是否可以将这种规则(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
推荐阅读
- html - 如何设置“价格”以在 Woocommerce 中居中对齐?
- sql-server - MSSQL NVarChar(1) 到 .Net 字符
- c++ - 使用基类向量和派生类指针进行对象切片
- django - 如何过滤来自 ansible tower api 查询的结果
- c++ - 为什么将 set::iterator 而不是 const_iterator 传递给函数违反了单一定义规则?
- javascript - useCallback 与类方法 [性能比较]
- typo3 - 在 TYPO3 9.5.5 版本中,PageTitleSeparator 不起作用
- javascript - 在 bootstrap-datetimepicker 中为每个单元格添加一天的价格
- android - android Kollin 应用程序中的“NetworkOnMainThreadException”使用由 swagger 生成的 kotlin-generated-client 文件
- python - “混合模型”的模型记录(例如,包括 KerasWrapper 的 SKlearn 管道)可能吗?