org.testng.ITestClass Java Examples

The following examples show how to use org.testng.ITestClass. 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: ReportIllNamedTest.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public void onBeforeClass(ITestClass testClass)
{
    String testClassName = testClass.getRealClass().getSimpleName();
    if (testClassName.startsWith("Test") || testClassName.startsWith("Benchmark")) {
        return;
    }
    if (testClassName.endsWith("IT")) {
        // integration test
        return;
    }

    // TestNG may or may not propagate listener's exception as test execution exception.
    // Therefore, instead of throwing, we terminate the JVM.
    System.err.println(format(
            "FATAL: Test class %s's name should start with Test",
            testClass.getRealClass().getName()));
    System.err.println("JVM will be terminated");
    System.exit(1);
}
 
Example #2
Source File: ReportUnannotatedMethods.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public void onBeforeClass(ITestClass testClass)
{
    Method[] publicMethods = testClass.getRealClass().getMethods();

    List<Method> unannotatedMethods = Arrays.stream(publicMethods)
            .filter(method -> method.getDeclaringClass() != Object.class)
            .filter(method -> !Modifier.isStatic(method.getModifiers()))
            .filter(method -> !method.isBridge())
            .filter(method -> !isTestMethod(method))
            .collect(toImmutableList());

    if (!unannotatedMethods.isEmpty()) {
        // TestNG may or may not propagate listener's exception as test execution exception.
        // Therefore, instead of throwing, we terminate the JVM.
        System.err.println(format(
                "FATAL: Test class %s has methods which are public but not explicitly annotated. Are they missing @Test?%s",
                testClass.getRealClass().getName(),
                unannotatedMethods.stream()
                        .map(Method::toString)
                        .collect(joining("\n\t\t", "\n\t\t", ""))));
        System.err.println("JVM will be terminated");
        System.exit(1);
    }
}
 
Example #3
Source File: LogTestDurationListener.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void onAfterClass(ITestClass testClass)
{
    if (!enabled) {
        return;
    }

    String name = getName(testClass);
    Duration duration = endTest(name);
    if (duration.compareTo(CLASS_LOGGING_THRESHOLD) > 0) {
        LOG.warn("Tests from %s took %s", name, duration);
    }
}
 
Example #4
Source File: LogTestDurationListener.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void onBeforeClass(ITestClass testClass)
{
    if (!enabled) {
        return;
    }

    beginTest(getName(testClass));
}
 
Example #5
Source File: AppiumParallelTestListener.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBeforeClass(ITestClass testClass) {
    try {
        String device = testClass.getXmlClass().getAllParameters().get("device");
        String hostName = testClass.getXmlClass().getAllParameters().get("hostName");
        DevicesByHost devicesByHost = HostMachineDeviceManager.getInstance().getDevicesByHost();
        AppiumDevice appiumDevice = devicesByHost.getAppiumDevice(device, hostName);
        deviceAllocationManager.allocateDevice(appiumDevice);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #6
Source File: CarbonBasedTestListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void onAfterClass(ITestClass iTestClass, IMethodInstance iMethodInstance) {

    MockInitialContextFactory.destroy();
    MicroserviceServer microserviceServer = microserviceServerMap.get(iMethodInstance.getInstance());
    if (microserviceServer != null) {
        microserviceServer.stop();
        microserviceServer.destroy();
        microserviceServerMap.remove(iMethodInstance.getInstance());
    }
}
 
Example #7
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void setClassContainer(final ITestClass clazz, final String uuid) {
    lock.writeLock().lock();
    try {
        classContainerUuidStorage.put(clazz, uuid);
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example #8
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private Optional<String> getClassContainer(final ITestClass clazz) {
    lock.readLock().lock();
    try {
        return Optional.ofNullable(classContainerUuidStorage.get(clazz));
    } finally {
        lock.readLock().unlock();
    }
}
 
Example #9
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 5 votes vote down vote up
public void onBeforeClass(final ITestClass testClass) {
    final String uuid = UUID.randomUUID().toString();
    final TestResultContainer container = new TestResultContainer()
            .setUuid(uuid)
            .setName(testClass.getName());
    getLifecycle().startTestContainer(container);
    setClassContainer(testClass, uuid);
}
 
Example #10
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void addClassContainerChild(final ITestClass clazz, final String childUuid) {
    lock.writeLock().lock();
    try {
        final String parentUuid = classContainerUuidStorage.get(clazz);
        if (nonNull(parentUuid)) {
            getLifecycle().updateTestContainer(
                    parentUuid,
                    container -> container.getChildren().add(childUuid)
            );
        }
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example #11
Source File: AppiumParallelTestListener.java    From AppiumTestDistribution with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onAfterClass(ITestClass iTestClass) {
    deviceAllocationManager.freeDevice();
}
 
Example #12
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private static String safeExtractTestClassName(final ITestClass testClass) {
    return firstNonEmpty(testClass.getTestName(), testClass.getName()).orElse("Undefined class name");
}
 
Example #13
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private static String safeExtractTestTag(final ITestClass testClass) {
    final Optional<XmlTest> xmlTest = Optional.ofNullable(testClass.getXmlTest());
    return xmlTest.map(XmlTest::getName).orElse("Undefined testng tag");
}
 
Example #14
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private static String safeExtractSuiteName(final ITestClass testClass) {
    final Optional<XmlTest> xmlTest = Optional.ofNullable(testClass.getXmlTest());
    return xmlTest.map(XmlTest::getSuite).map(XmlSuite::getName).orElse("Undefined suite");
}
 
Example #15
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 #16
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 4 votes vote down vote up
public void onAfterClass(final ITestClass testClass) {
    getClassContainer(testClass).ifPresent(uuid -> {
        getLifecycle().stopTestContainer(uuid);
        getLifecycle().writeTestContainer(uuid);
    });
}
 
Example #17
Source File: ReactiveStreamsArquillianTck.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Override
public void onAfterClass(ITestClass testClass) {
}
 
Example #18
Source File: ReactiveStreamsArquillianTck.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Override
public void onBeforeClass(ITestClass testClass) {
    System.out.println(testClass.getName() + ":");
}
 
Example #19
Source File: ReportUnannotatedMethods.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public void onAfterClass(ITestClass testClass) {}
 
Example #20
Source File: ReportIllNamedTest.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public void onAfterClass(ITestClass iTestClass) {}
 
Example #21
Source File: LogTestDurationListener.java    From presto with Apache License 2.0 4 votes vote down vote up
private static String getName(ITestClass testClass)
{
    return testClass.getName();
}