简体   繁体   English

以编程方式无法通过Maven测试JUnit5测试

[英]Failing Maven test JUnit5 test programmatically

I do execute my Maven tests with JUnit5, where all the test classes have the 我确实使用JUnit5执行了Maven测试,其中所有测试类都具有

@ExtendWith({ProcessExtension.class})

annotation. 注解。 This extension must fail test methods according to a special logic in the if it is the case. 在这种情况下,此扩展必须根据特殊逻辑使测试方法失败。 But I have no idea how. 但是我不知道如何。

The method 方法

@Override
public void afterEach(ExtensionContext context) {
    ...
}

gets this context parameter but the is no way to fail the already executed test method. 获取此上下文参数,但无法使已经执行的测试方法失败。 How could I notify the Maven that the method has failed? 我如何通知Maven方法已失败?

KI KI

I think you can use the fail method for this: 我认为您可以为此使用fail方法:

import static org.junit.jupiter.api.Assertions.fail;


public class ProcessExtension implements AfterEachCallback {

    @Override
    public void afterEach(ExtensionContext context) {
        boolean failTest = ...;

        if (failTest) {
            fail("test failed");
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM