org.testng.IClass Java Examples

The following examples show how to use org.testng.IClass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private List<Label> getLabels(final ITestNGMethod method, final IClass iClass) {
    final List<Label> labels = new ArrayList<>();
    getMethod(method)
            .map(AnnotationUtils::getLabels)
            .ifPresent(labels::addAll);
    getClass(iClass)
            .map(AnnotationUtils::getLabels)
            .ifPresent(labels::addAll);

    getMethod(method)
            .map(this::getSeverity)
            .filter(Optional::isPresent)
            .orElse(getClass(iClass).flatMap(this::getSeverity))
            .map(ResultsUtils::createSeverityLabel)
            .ifPresent(labels::add);
    return labels;
}
 
Example #2
Source File: BaseTest.java    From video-recorder-java with MIT License 6 votes vote down vote up
protected ITestResult prepareMock(Class<?> tClass, Method method) {
  ITestResult result = mock(ITestResult.class);
  IClass clazz = mock(IClass.class);
  ITestNGMethod testNGMethod = mock(ITestNGMethod.class);
  ConstructorOrMethod cm = mock(ConstructorOrMethod.class);
  String methodName = method.getName();
  when(result.getTestClass()).thenReturn(clazz);
  when(result.getTestClass().getRealClass()).thenReturn(tClass);
  when(clazz.getName()).thenReturn(this.getClass().getName());
  when(result.getMethod()).thenReturn(testNGMethod);
  when(cm.getMethod()).thenReturn(method);
  when(result.getMethod().getConstructorOrMethod()).thenReturn(cm);
  when(testNGMethod.getMethodName()).thenReturn(methodName);
  ITestContext context = mock(ITestContext.class);
  when(result.getTestContext()).thenReturn(context);
  XmlTest xmlTest = new XmlTest();
  XmlSuite suite = new XmlSuite();
  xmlTest.setXmlSuite(suite);
  suite.setListeners(Arrays.asList(VideoListener.class.getName()));
  when(context.getCurrentXmlTest()).thenReturn(xmlTest);
  return result;
}
 
Example #3
Source File: CustomHTMLReporter.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private SortedMap<IClass, List<ITestResult>> sortByTestClass(IResultMap results) {
    SortedMap<IClass, List<ITestResult>> sortedResults = new TreeMap<IClass, List<ITestResult>>(CLASS_COMPARATOR);
    for (ITestResult result : results.getAllResults()) {
        List<ITestResult> resultsForClass = sortedResults.get(result.getTestClass());
        if (resultsForClass == null) {
            resultsForClass = new ArrayList<>();
            sortedResults.put(result.getTestClass(), resultsForClass);
        }
        int index = Collections.binarySearch(resultsForClass, result, RESULT_COMPARATOR);
        if (index < 0) {
            index = Math.abs(index + 1);
        }
        resultsForClass.add(index, result);
    }
    return sortedResults;
}
 
Example #4
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private List<Link> getLinks(final ITestNGMethod method, final IClass iClass) {
    final List<Link> links = new ArrayList<>();
    getMethod(method)
            .map(AnnotationUtils::getLinks)
            .ifPresent(links::addAll);
    getClass(iClass)
            .map(AnnotationUtils::getLinks)
            .ifPresent(links::addAll);
    return links;
}
 
Example #5
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private boolean isFlaky(final ITestNGMethod method, final IClass iClass) {
    final boolean flakyMethod = getMethod(method)
            .map(m -> m.isAnnotationPresent(Flaky.class))
            .orElse(false);
    final boolean flakyClass = getClass(iClass)
            .map(clazz -> clazz.isAnnotationPresent(Flaky.class))
            .orElse(false);
    return flakyMethod || flakyClass;
}
 
Example #6
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private boolean isMuted(final ITestNGMethod method, final IClass iClass) {
    final boolean mutedMethod = getMethod(method)
            .map(m -> m.isAnnotationPresent(Muted.class))
            .orElse(false);
    final boolean mutedClass = getClass(iClass)
            .map(clazz -> clazz.isAnnotationPresent(Muted.class))
            .orElse(false);
    return mutedMethod || mutedClass;
}
 
Example #7
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"Indentation", "PMD.ExcessiveMethodLength", "deprecation"})
protected void startTestCase(final ITestContext context,
                             final ITestNGMethod method,
                             final IClass iClass,
                             final Object[] params,
                             final String parentUuid,
                             final String uuid) {
    final ITestClass testClass = method.getTestClass();
    final List<Label> labels = new ArrayList<>();
    labels.addAll(getProvidedLabels());
    labels.addAll(Arrays.asList(
            //Packages grouping
            createPackageLabel(testClass.getName()),
            createTestClassLabel(testClass.getName()),
            createTestMethodLabel(method.getMethodName()),

            //xUnit grouping
            createParentSuiteLabel(safeExtractSuiteName(testClass)),
            createSuiteLabel(safeExtractTestTag(testClass)),
            createSubSuiteLabel(safeExtractTestClassName(testClass)),

            //Timeline grouping
            createHostLabel(),
            createThreadLabel(),

            createFrameworkLabel("testng"),
            createLanguageLabel("java")
    ));
    labels.addAll(getLabels(method, iClass));
    final List<Parameter> parameters = getParameters(context, method, params);
    final TestResult result = new TestResult()
            .setUuid(uuid)
            .setHistoryId(getHistoryId(method, parameters))
            .setName(getMethodName(method))
            .setFullName(getQualifiedName(method))
            .setStatusDetails(new StatusDetails()
                    .setFlaky(isFlaky(method, iClass))
                    .setMuted(isMuted(method, iClass)))
            .setParameters(parameters)
            .setLinks(getLinks(method, iClass))
            .setLabels(labels);
    processDescription(getClass().getClassLoader(), method.getConstructorOrMethod().getMethod(), result);
    getLifecycle().scheduleTestCase(parentUuid, result);
    getLifecycle().startTestCase(uuid);
}
 
Example #8
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private Optional<Class<?>> getClass(final IClass iClass) {
    return Optional.ofNullable(iClass)
            .map(IClass::getRealClass);
}