本文整理汇总了Java中org.testng.ITestNGMethod.getRealClass方法的典型用法代码示例。如果您正苦于以下问题:Java ITestNGMethod.getRealClass方法的具体用法?Java ITestNGMethod.getRealClass怎么用?Java ITestNGMethod.getRealClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.testng.ITestNGMethod
的用法示例。
在下文中一共展示了ITestNGMethod.getRealClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeClassLevel
import org.testng.ITestNGMethod; //导入方法依赖的package包/类
private void initializeClassLevel(ITestContext iTestContext) {
classBrowsers.clear();
ITestNGMethod[] testMethods = iTestContext.getAllTestMethods();
for (ITestNGMethod method : testMethods) {
Class<?> testClass = method.getRealClass();
for (Field field : ReflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
boolean fieldIsStatic = Modifier.isStatic(field.getModifiers());
boolean fieldIsABrowser = Browser.class.isAssignableFrom(field.getType());
boolean fieldIsAnnotatedAsResource = field.getAnnotation(Resource.class) != null;
boolean isNoDuplicate = fieldIsNoDuplicateOfAnExistingClassBrowserField(field);
if (fieldIsStatic && fieldIsABrowser && fieldIsAnnotatedAsResource && isNoDuplicate) {
classBrowserFields.add(field);
classBrowsers.add(new ClassTestBrowser(field));
}
}
}
}
示例2: getParametersForMethod
import org.testng.ITestNGMethod; //导入方法依赖的package包/类
/**
* Obtains list of parameter sets for test method based on defined data provider.
* If no data provider is defined then {@link Optional#empty()} is returned.
* This method takes into consideration only data providers defined through annotation.
*
* @param method to be examined
* @return list of parameter sets
*/
public static Optional<Object[][]> getParametersForMethod(ITestNGMethod method)
{
Test testAnnotation = method.getConstructorOrMethod().getMethod().getAnnotation(Test.class);
Class dataProviderClass = testAnnotation.dataProviderClass();
if (dataProviderClass == null || dataProviderClass == Object.class) {
dataProviderClass = method.getRealClass();
}
String dataProviderName = testAnnotation.dataProvider();
if (dataProviderName.isEmpty()) {
return Optional.empty();
}
Optional<Method> dataProviderMethodOptional = asList(dataProviderClass.getMethods()).stream().filter(
m -> {
DataProvider annotation = m.getAnnotation(DataProvider.class);
return annotation != null && annotation.name().equals(dataProviderName);
}
).findFirst();
if (dataProviderMethodOptional.isPresent()) {
try {
return Optional.of((Object[][]) dataProviderMethodOptional.get().invoke(null));
}
catch (Exception e) {
throw new RuntimeException("Exception while calling data provider for " + method, e);
}
}
else {
return Optional.empty();
}
}
示例3: injectConfigurationValuesIntoStaticFields
import org.testng.ITestNGMethod; //导入方法依赖的package包/类
private void injectConfigurationValuesIntoStaticFields(ITestContext iTestContext) {
ITestNGMethod[] testMethods = iTestContext.getAllTestMethods();
for (ITestNGMethod method : testMethods) {
Class<?> testClass = method.getRealClass();
if (configurationValuesAnnotationIsUsedOnClassLevel(testClass)) {
Configuration configuration = getPrimaryBrowser().getBrowser().getConfiguration();
ConfigurationValueInjector.injectStatics(configuration, testClass);
}
}
}