TestNG:如何从 DataProvider 获取即将由 Factory 创建的 class
TestNG: How to get class that is about to create by Factory from DataProvider
我在构造函数中有一个 class 和 @Factory(dataProvider = "dp")
。
我怎样才能获得 class inside data provider?
class Test {
@Factory(dataProvider = "dp")
public Test(int i) {
//... some code
}
@DataProvider
public static Object[][] dp(ITestContext context, Method method) {
// need to get currently created class by factory
// method is null here
// not found any way to obtain this class from test context
}
}
在此示例中,我可以使用硬编码的 class 名称,但在现实世界中,数据提供者位于父级 class 中(或只是分开 class)
只需执行以下操作:
class Test {
@Factory(dataProvider = "dp")
public Test(int i) {
//... some code
}
@DataProvider
public static Object[][] dp(ConstructorOrMethod com) {
Class<?> testClass = com.getConstructor().getDeclaringClass();
}
}
我在构造函数中有一个 class 和 @Factory(dataProvider = "dp")
。
我怎样才能获得 class inside data provider?
class Test {
@Factory(dataProvider = "dp")
public Test(int i) {
//... some code
}
@DataProvider
public static Object[][] dp(ITestContext context, Method method) {
// need to get currently created class by factory
// method is null here
// not found any way to obtain this class from test context
}
}
在此示例中,我可以使用硬编码的 class 名称,但在现实世界中,数据提供者位于父级 class 中(或只是分开 class)
只需执行以下操作:
class Test {
@Factory(dataProvider = "dp")
public Test(int i) {
//... some code
}
@DataProvider
public static Object[][] dp(ConstructorOrMethod com) {
Class<?> testClass = com.getConstructor().getDeclaringClass();
}
}