【发布时间】:2018-05-08 14:20:45
【问题描述】:
因此,有一个庞大的 java 测试框架项目与各种硬件组件一起工作。问题是:在@Beforemethod 中出现异常/硬件故障等情况时,@Aftermethod 无法动态地决定将哪些资源设置回其相应的原始状态/值。这可能会危及依赖相同硬件元素状态的后续测试用例(主要是假阴性)。
我想分别在遇到错误之前反转@BeforeMethod中发生的所有对象修改。这样我可以使其他测试更容易出错(得到假阴性的机会更少)。
为每个套件定义一个原子状态不是一种选择(在我看来) - 太麻烦了,需要大量的代码修改,因此为每个对象设置原子状态可能需要比应有的更多时间。
有什么建议吗?您知道针对此类问题的任何好的测试指南/模式吗?
编辑:
TestClass1{
@BeforeMethod
method(){
resource1.setfoo("foo");
resource1.setbar("bar");
...
resource7.setfoo("bar"); // -> hw error occurs, testmethod1 is not run
...
}
testmethod1(){
foo.bar();
}
}
TestClass2{
testmethod2(){
assertTrue(resource1.doSomething()); /*fails because some combination of
the resource modifications that happened in the previous @Beforemethod
in TestClass1 changed the hardware operation in some way. */
}
}
【问题讨论】:
-
为什么不能在 @Beforemethod 本身中处理这些问题?
-
您能帮忙编辑您的问题并在帖子中添加一个示例,以显示您在说什么吗?