Java Junit将@Test方法中的一些值传递到@Rule方法中
我使用Junit作为Selenium框架的一部分运行测试。我需要将实际测试方法中的一些值记录到另一种方法中Java Junit将@Test方法中的一些值传递到@Rule方法中,java,selenium,junit,Java,Selenium,Junit,我使用Junit作为Selenium框架的一部分运行测试。我需要将实际测试方法中的一些值记录到另一种方法中 @Rule public final RuleChain rules = RuleChain.outerRule( Watcher.newBuilder() .addCustomProperty("key", "value") .addCustomProperty("
@Rule
public final RuleChain rules =
RuleChain.outerRule(
Watcher.newBuilder()
.addCustomProperty("key", "value")
.addCustomProperty("key", "value")
.addCustomProperty("key", "value")
);
@Test
public void someTest() {
String a = "newValue"; //this need to be passed into @Rule "value"
String b = "newValue"; //this need to be passed into @Rule "value"
String c = "newValue"; //this need to be passed into @Rule "value"
}
我只是在猜。但是,为什么不将这些值设置为测试类的实例属性并在规则中提取它们呢?尽管测试最佳实践表明JUnit测试应该是自包含的,而不是相互依赖的。考虑到它们可以以随机顺序执行。。。