【发布时间】:2017-03-19 12:32:45
【问题描述】:
在我的@Test 方法之上,我有一个注释,其中包含@DataProvider 应该从中提取数据的文件名。我尝试在@BeforeMethod 中初始化该文件,但我没有成功,因为@BeforeMethod 运行AFTER @DataProvider。
我需要在 @BeforeMethod 中初始化 File 的原因是我只能从该方法中知道运行了哪个 @Test 方法,然后使用文件名提取其注释。另外,我想在每个 @Test 方法运行之前执行它。我怎样才能使这件事起作用?
String fileName;
@MyAnnotation(fileName="abc.txt")
@Test(dataProvider = "getData")
public void test(DataFromFile data) {
...showData();
}
@BeforeMethod
public void beforeMethod(Method invokingMethod) {
fileName ... = invokingMethod.getAnnotation(MyAnnotation.class).fileName();
}
@DataProvider
public Object[][] getData() {
... initialize new File(fileName);
...
}
【问题讨论】:
-
这个类中有多少
@MyAnnotation(fileName="abc.txt")注解的方法? -
一个。这对问题有何影响?