@DisabledIfSystemProperty() 不适用于 afterEach 或 afterAll 挂钩
@DisabledIfSystemProperty() not working on afterEach or afterAll hook
也许我误解了可以在哪里使用条件注释,但我正在尝试 运行 一个 afterEach 挂钩,或者仅当传入系统 属性 时才使用 afterAll 挂钩。
例如:
mvn test -DrunTearDownScript=false
以及我的 afterEach 钩子:
@AfterAll
@DisabledIfSystemProperty(named = "runTearDownScript", matches = "false")
void clearDownTestEnvironment() {
System.out.println(System.getProperty("runTearDownScript"));
}
在上面的例子中,我希望 println
不会被打印,但它是 "false"。
我想我可以在钩子中写下我自己的条件,但理想情况下使用注释看起来更干净。
如有任何帮助,我们将不胜感激。谢谢。
Perhaps I've misunderstood where the conditional annotations can be used...
是的。它们只能用于 "a container or (a) test (method)".
复制自https://junit.org/junit5/docs/current/user-guide/#writing-tests-conditional-execution
The ExecutionCondition extension API in JUnit Jupiter allows developers to either enable or disable a container or test based on certain conditions programmatically.
[...]
Each of the conditional annotations listed in the following sections can only be declared once on a given test interface, test class, or test method.
[...]
2.7.3 System Property Conditions
A container or test may be enabled or disabled based on the value of the named JVM system property via the @EnabledIfSystemProperty and @DisabledIfSystemProperty annotations. The value supplied via the matches attribute will be interpreted as a regular expression.
也许我误解了可以在哪里使用条件注释,但我正在尝试 运行 一个 afterEach 挂钩,或者仅当传入系统 属性 时才使用 afterAll 挂钩。
例如:
mvn test -DrunTearDownScript=false
以及我的 afterEach 钩子:
@AfterAll
@DisabledIfSystemProperty(named = "runTearDownScript", matches = "false")
void clearDownTestEnvironment() {
System.out.println(System.getProperty("runTearDownScript"));
}
在上面的例子中,我希望 println
不会被打印,但它是 "false"。
我想我可以在钩子中写下我自己的条件,但理想情况下使用注释看起来更干净。
如有任何帮助,我们将不胜感激。谢谢。
Perhaps I've misunderstood where the conditional annotations can be used...
是的。它们只能用于 "a container or (a) test (method)".
复制自https://junit.org/junit5/docs/current/user-guide/#writing-tests-conditional-execution
The ExecutionCondition extension API in JUnit Jupiter allows developers to either enable or disable a container or test based on certain conditions programmatically.
[...]
Each of the conditional annotations listed in the following sections can only be declared once on a given test interface, test class, or test method.
[...]
2.7.3 System Property Conditions
A container or test may be enabled or disabled based on the value of the named JVM system property via the @EnabledIfSystemProperty and @DisabledIfSystemProperty annotations. The value supplied via the matches attribute will be interpreted as a regular expression.