JUnit 5 AfterEach 方法在测试方法完成之前调用

JUnit 5 AfterEach method calling before test method finished

我的测试方法如下所示:

@Test
test_testName()
{
   startSomeWorkInParallel();
   // waiting with await() static method and some timeout
   waitUntilActionFinishedOrFailAssert(timeout);
   checkResults();
}

并行工作使用可关闭资源来控制生命周期,并且此资源正在 @AfterEach 方法中关闭:

@AfterEach
void afterEach()
{
    resource.close();
}

问题是:afterEach() 方法在 test_testName() 完成工作之前和等待超时到期之前调用。

怎么可能?我该如何解决?

等待方法原问题:

 waitUntilActionFinishedOrFailAssert(timeout);

这不是 JUnit 的问题。修复这个方法解决了顺序执行afterEach()方法的问题。