【发布时间】:2017-04-02 03:23:24
【问题描述】:
前言:
我有以下注释和 junit 测试的规则初始化部分。 目标是使用不同的配置并使测试尽可能简单易用。
// Annotation
@Retention(RetentionPolicy.RUNTIME)
public @interface ConnectionParams {
public String username();
public String password() default "";
}
// Part of the test
@ConnectionParams(username = "john")
@Rule
public ConnectionTestRule ctr1 = new ConnectionTestRule();
@ConnectionParams(username = "doe", password = "secret")
@Rule
public ConnectionTestRule ctr2 = new ConnectionTestRule();
现在我想访问下面TestRule中的注解参数,但是没有找到任何注解。
public class ConnectionTestRule implements TestRule {
public Statement apply(Statement arg0, Description arg1) {
if (this.getClass().isAnnotationPresent(ConnectionParams.class)) {
... // do stuff
}
}
}
如何访问 TestRule 中的注释?
【问题讨论】:
标签: java spring junit annotations