有没有办法在我的TestNG注释中使用 dependsOnMethods 进行以groovy编写的测试?
class WarehouseBehavior {
@Test
void shouldHaveWarehouse() {
def warehouse = registry.getService Warehouse.class
assertNotNull warehouse
}
@Test(dependsOnMethods = ['shouldHaveWarehouse'])
void shouldStoreDataInWarehouse() {
def warehouse = registry.getService Warehouse.class
warehouse.store(['a': 'b', 'c': 'd'])
}
}
我要么在这里丢失一些东西,要么groovy只是不支持这种类型的注释,因为类似的代码在Java中运行得非常好,而在groovy中运行它会给我以下错误
WarehouseBehavior.shouldStoreDataInWarehouse() is depending on method public void WarehouseBehavior.shouldHaveWarehouse(), which is not annotated with @Test
答案 0 :(得分:0)
Test
方法具有包范围。
明确声明public
为:
@Test
public void shouldHaveWarehouse() {
// .....
}
答案 1 :(得分:0)
注意:这不是(完整)回复IMO,但它更多的是解决方法。只需将其添加到此处,以防有人可以改进此答案并提供更多见解。
面对与Groovy测试相同的问题,只有解决方法,我发现到目前为止,这两个方法都在同一个组中然后才能工作。像这样的东西
class WarehouseBehavior {
@Test(groups =['somegroup'])
void shouldHaveWarehouse() {
def warehouse = registry.getService Warehouse.class
assertNotNull warehouse
}
@Test(groups =['somegroup'], dependsOnMethods = ['shouldHaveWarehouse'])
void shouldStoreDataInWarehouse() {
def warehouse = registry.getService Warehouse.class
warehouse.store(['a': 'b', 'c': 'd'])
}
}