尝试在 groovy 文件中创建规则的一些变体,我想到@Rule 不描述声明,而是描述分配。因此,跑步者在加载测试时,会尝试每条规则以正确分配。
//Correct variants:
@Rule
public ErrorCollector collector1= new ErrorCollector();
public ErrorCollector collector2= null;
@Rule
collector2= new ErrorCollector();
public ErrorCollector collector3;
@Rule
collector3= new ErrorCollector();
// incorrect variants:
@Rule
public ErrorCollector collector4= null;
@Rule
public ErrorCollector collector5;
@Rule
public ErrorCollector collector5=somethingThatIsNotRule;
@Rule
public ErrorCollector collector5=anotherRule;
但是,后来我遇到了一些自相矛盾的变体:
//these lines are not only taken by the runner, but also passed without errors:
public ErrorCollector collector6;
{
@Rule
collector6= null;
}
public ErrorCollector collector7=null;
{
@Rule
collector7= null;
}
它的逻辑是什么?
这似乎是 Runner 中的一个错误 - runner 在构建测试之前进行了过多的检查。