Java 类org.testng.TestListenerAdapter 实例源码

项目:TestNG-Foundation    文件:ArtifactCollectorTest.java   
@Test
public void verifyHappyPath() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("testPassed");
    testNG.run();

    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    ITestResult result = tla.getPassedTests().get(0);
    assertNull(UnitTestArtifact.getCaptureState(result), "Artifact provider capture state should be 'null'");
    assertNull(UnitTestCapture.getArtifactPath(result), "Artifact capture should not have been requested");
}
项目:TestNG-Foundation    文件:ArtifactCollectorTest.java   
@Test
public void verifyCaptureOnFailure() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("testFailed");
    testNG.run();

    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    ITestResult result = tla.getFailedTests().get(0);
    assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state");
    assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present");
}
项目:TestNG-Foundation    文件:ArtifactCollectorTest.java   
@Test
public void verifyCanNotCapture() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("canNotCapture");
    testNG.run();

    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    ITestResult result = tla.getFailedTests().get(0);
    assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAN_NOT_CAPTURE, "Incorrect artifact provider capture state");
    assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present");
}
项目:TestNG-Foundation    文件:ArtifactCollectorTest.java   
@Test
public void verifyWillNotCapture() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("willNotCapture");
    testNG.run();

    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    ITestResult result = tla.getFailedTests().get(0);
    assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_FAILED, "Incorrect artifact provider capture state");
    assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present");
}
项目:TestNG-Foundation    文件:ArtifactCollectorTest.java   
@Test
public void verifyOnDemandCapture() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("onDemandCapture");
    testNG.run();

    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    ITestResult result = tla.getPassedTests().get(0);
    assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state");
    assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present");
}
项目:TestNG-Foundation    文件:ExecutionFlowControllerTest.java   
@Test
public void testAttributeHandOff() {

    ExecutionFlowController efc = new ExecutionFlowController();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{HappyPathClass.class});
    testNG.addListener((ITestNGListener) efc);
    testNG.addListener((ITestNGListener) tla);
    testNG.run();

    assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");

    assertEquals(tla.getPassedTests().size(), 2, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");

    assertEquals(HappyPathClass.fromBefore, HappyPathClass.VALUE, "Incorrect [before] value");
    assertEquals(HappyPathClass.fromMethod, HappyPathClass.VALUE, "Incorrect [method] value");
    assertEquals(HappyPathClass.fromAfter, HappyPathClass.VALUE, "Incorrect [after] value");

}
项目:TestNG-Foundation    文件:ExecutionFlowControllerTest.java   
@Test
public void testSkipFromMethod() {

    ExecutionFlowController efc = new ExecutionFlowController();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{SkipFromMethod.class});
    testNG.addListener((ITestNGListener) efc);
    testNG.addListener((ITestNGListener) tla);
    testNG.run();

    assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");

    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");
    assertEquals(tla.getSkippedTests().get(0).getName(), "testMethod", "Incorrect skipped test name");

    assertEquals(SkipFromMethod.fromBefore, SkipFromMethod.VALUE, "Incorrect [before] value");
    assertEquals(SkipFromMethod.fromMethod, SkipFromMethod.VALUE, "Incorrect [method] value");
    assertEquals(SkipFromMethod.fromAfter, SkipFromMethod.VALUE, "Incorrect [after] value");

}
项目:revature-automation-framework-remastered    文件:TestThread.java   
@Override
public void run() {

    try {
        TestListenerAdapter tla = new TestListenerAdapter();
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[] { HybridTest.class });
        //testng.settes
        testng.addListener(tla);
        testng.run();
    }catch (Exception e) {
        e.printStackTrace();
        System.out.println("Thread " +  threadName + " interrupted.");
    }

    System.out.println("Thread " +  threadName + " exiting.");
}
项目:aerial    文件:AerialTestNGRunnerTest.java   
@Test
public void testRunSampleTestNGClass() throws Exception {
    TestListenerAdapter tla = new TestListenerAdapter();
    TestNG testng = new TestNG();
    testng.setTestClasses(new Class[] {TestSubClass.class});
    testng.addListener(tla);
    testng.run();

    for (String item : this.outputFiles) {
        File file = new File(item);
        Assert.assertTrue(
                "The element '" + file.getAbsolutePath() + "' wasn't found",
                file.exists());
    }
    for (String method : this.expectedMethods) {
        Assert.assertTrue(
                "Unable to find the call of method: " + method,
                AerialGluCode.getCallsList().contains(method));
    }
}
项目:TestNG-Foundation    文件:ExecutionFlowControllerTest.java   
@Test
public void testSkipFromBefore() {

    ExecutionFlowController efc = new ExecutionFlowController();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{SkipFromBefore.class});
    testNG.addListener((ITestNGListener) efc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setConfigFailurePolicy(FailurePolicy.CONTINUE);
    testNG.run();

    assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");

    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration skip count");
    assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");
    ITestResult methodResult = tla.getSkippedTests().get(0);
    assertEquals(methodResult.getName(), "testMethod", "Incorrect skipped test name");

    assertEquals(SkipFromBefore.fromBefore, SkipFromBefore.VALUE, "Incorrect [before] value");
    assertEquals(methodResult.getAttribute(SkipFromBefore.ATTRIBUTE), SkipFromBefore.VALUE, "Incorrect [method] value");
    assertEquals(SkipFromBefore.fromAfter, SkipFromBefore.VALUE, "Incorrect [after] value");

}
项目:TestNG-Foundation    文件:ExecutionFlowControllerTest.java   
@Test
public void testMethodListenerExtension() {

    ExecutionFlowController efc = new ExecutionFlowController();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{MethodListenerExtension.class});
    testNG.addListener((ITestNGListener) efc);
    testNG.addListener((ITestNGListener) tla);
    testNG.run();

    assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");

    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");

    assertTrue(MethodListenerExtension.beforeMethodBefore, "Incorrect [beforeMethod] 'before' value");
    assertTrue(MethodListenerExtension.testMethodBefore, "Incorrect [testMethod] 'before' value");
    assertTrue(MethodListenerExtension.afterMethodBefore, "Incorrect [afterMethod] 'before' value");
    assertTrue(MethodListenerExtension.beforeMethodAfter, "Incorrect [beforeMethod] 'after' value");
    assertTrue(MethodListenerExtension.testMethodAfter, "Incorrect [testMethod] 'after' value");
    assertTrue(MethodListenerExtension.afterMethodAfter, "Incorrect [afterMethod] 'after' value");

}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyTestFailed() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("testFailed");
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));
    assertTrue(chainedListener.configSuccess.contains("afterSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("afterSuccess"));

    assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));
    assertTrue(chainedListener.testMethodBefore.contains("testFailed"));
    assertTrue(chainedListener.testMethodAfter.contains("testFailed"));
    assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess"));
    assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess"));

    assertTrue(chainedListener.testStarted.contains("testFailed"));
    assertTrue(chainedListener.testFailure.contains("testFailed"));

}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyTestSkipped() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("testSkipped");
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));
    assertTrue(chainedListener.configSuccess.contains("afterSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("afterSuccess"));

    assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));
    assertTrue(chainedListener.testMethodBefore.contains("testSkipped"));
    assertTrue(chainedListener.testMethodAfter.contains("testSkipped"));
    assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess"));
    assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess"));

    assertTrue(chainedListener.testStarted.contains("testSkipped"));
    assertTrue(chainedListener.testSkipped.contains("testSkipped"));

}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyFailAndPass() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("failAndPass");
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 3, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 1, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));
    assertTrue(chainedListener.configSuccess.contains("afterSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("afterSuccess"));

    assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));
    assertTrue(chainedListener.testMethodBefore.contains("failAndPass"));
    assertTrue(chainedListener.testMethodAfter.contains("failAndPass"));
    assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess"));
    assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess"));

    assertTrue(chainedListener.testStarted.contains("failAndPass"));
    assertTrue(chainedListener.testCurved.contains("failAndPass"));

}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyBeforeFailed() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("beforeFailed");
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 1, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration method skip count");

    assertTrue(chainedListener.configFailure.contains("beforeFailure"));
    assertTrue(chainedListener.configSkipped.contains("afterSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("beforeFailure"));

    assertTrue(chainedListener.beforeMethodBefore.contains("beforeFailure"));
    assertTrue(chainedListener.beforeMethodAfter.contains("beforeFailure"));
    assertTrue(chainedListener.testMethodBefore.contains("skipBeforeFailed"));
    assertTrue(chainedListener.testMethodAfter.contains("skipBeforeFailed"));

    assertTrue(chainedListener.testStarted.contains("skipBeforeFailed"));
    assertTrue(chainedListener.testSkipped.contains("skipBeforeFailed"));

}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyBeforeSkipped() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("beforeSkipped");
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 2, "Incorrect configuration method skip count");

    assertTrue(chainedListener.configSkipped.contains("beforeSkipped"));
    assertTrue(chainedListener.configSkipped.contains("afterSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("beforeSkipped"));

    assertTrue(chainedListener.beforeMethodBefore.contains("beforeSkipped"));
    assertTrue(chainedListener.beforeMethodAfter.contains("beforeSkipped"));
    assertTrue(chainedListener.testMethodBefore.contains("skipBeforeSkipped"));
    assertTrue(chainedListener.testMethodAfter.contains("skipBeforeSkipped"));

    assertTrue(chainedListener.testStarted.contains("skipBeforeSkipped"));
    assertTrue(chainedListener.testSkipped.contains("skipBeforeSkipped"));

}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyAfterFailed() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("afterFailed");
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 1, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));
    assertTrue(chainedListener.configFailure.contains("afterFailure"));
    assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("afterFailure"));

    assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));
    assertTrue(chainedListener.testMethodBefore.contains("testAfterFailed"));
    assertTrue(chainedListener.testMethodAfter.contains("testAfterFailed"));
    assertTrue(chainedListener.afterMethodBefore.contains("afterFailure"));
    assertTrue(chainedListener.afterMethodAfter.contains("afterFailure"));

    assertTrue(chainedListener.testStarted.contains("testAfterFailed"));
    assertTrue(chainedListener.testSuccess.contains("testAfterFailed"));

}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyAfterSkipped() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("afterSkipped");
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration method skip count");

    assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));
    assertTrue(chainedListener.configSkipped.contains("afterSkipped"));
    assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("afterSkipped"));

    assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));
    assertTrue(chainedListener.testMethodBefore.contains("testAfterSkipped"));
    assertTrue(chainedListener.testMethodAfter.contains("testAfterSkipped"));
    assertTrue(chainedListener.afterMethodBefore.contains("afterSkipped"));
    assertTrue(chainedListener.afterMethodAfter.contains("afterSkipped"));

    assertTrue(chainedListener.testStarted.contains("testAfterSkipped"));
    assertTrue(chainedListener.testSuccess.contains("testAfterSkipped"));

}
项目:unitils    文件:TestNGTest1.java   
public static void main(String[] args) {
    TestListenerAdapter tla = new TextReporter("test", 3);
    TestNG testng = new TestNG();
    testng.setTestClasses(new Class[] { TestNGTest.class});
    testng.addListener(tla);
    testng.run();
}
项目:unitils    文件:TestNGTest.java   
public static void main(String[] args) {
    TestListenerAdapter tla = new TextReporter("test", 3);
    TestNG testng = new TestNG();
    testng.setTestClasses(new Class[] { TestNGTest.class});
    testng.addListener(tla);
    testng.run();
}
项目:test-analyzer    文件:TestNgTestRunner.java   
@Override
public ITestRunResult runTest(Class<?> testClass, String testcaseName) {
    TestNG testng = new TestNG();
    TestListenerAdapter listener = new TestListenerAdapter();

    testng.setTestClasses(new Class[] { testClass });
    testng.setMethodInterceptor(new SelectMethodByNameInterceptor(testcaseName));
    testng.addListener(listener);

    testng.run();

    return new TestNgRunResult(listener);
}
项目:testng-remote    文件:SimpleBaseTest.java   
protected void verifyPassedTests(TestListenerAdapter tla, String... methodNames) {
  Iterator<ITestResult> it = tla.getPassedTests().iterator();
  Assert.assertEquals(tla.getPassedTests().size(), methodNames.length);

  int i = 0;
  while (it.hasNext()) {
    Assert.assertEquals(it.next().getName(), methodNames[i++]);
  }
}
项目:incubator-atlas    文件:SecureEmbeddedServerTestBase.java   
/**
 * Runs the existing webapp test cases, this time against the initiated secure server instance.
 * @throws Exception
 */
@Test
public void runOtherSuitesAgainstSecureServer() throws Exception {
    final PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
    // setup the credential provider
    setupCredentials();

    try {
        secureEmbeddedServer = new SecureEmbeddedServer(securePort, TestUtils.getWarPath()) {
            @Override
            protected PropertiesConfiguration getConfiguration() {
                return configuration;
            }
        };
        secureEmbeddedServer.server.start();

        TestListenerAdapter tla = new TestListenerAdapter();
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[]{AdminJerseyResourceIT.class, EntityJerseyResourceIT.class,
                MetadataDiscoveryJerseyResourceIT.class,
                TypesJerseyResourceIT.class});
        testng.addListener(tla);
        testng.run();

    } finally {
        secureEmbeddedServer.server.stop();
    }

}
项目:Sapient    文件:TestngRun.java   
public  TestngRun() {
    tng=new TestNG();
    listener=new TestListenerAdapter();//定义监听器类型
    tng.addListener(listener);
    xmlFileList=new ArrayList<>();//记录测试使用的xml文件路径列表
    testReport=new TestReport();//记录测试报告测试报告信息
    runInfo=new TestRunInfo();
}
项目:QTAF    文件:TestngRun.java   
public  TestngRun() {
    tng=new TestNG();
    listener=new TestListenerAdapter();//定义监听器类型
    tng.addListener(listener);
    xmlFileList=new ArrayList<>();//记录测试使用的xml文件路径列表
    testReport=new TestReport();//记录测试报告测试报告信息
    runInfo=new TestRunInfo();
}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyHappyPath() {

    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ListenerChainTestCases.class, ListenerChainTestFactory.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("happyPath");
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 2, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));
    assertTrue(chainedListener.configSuccess.contains("afterSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeConfig.contains("afterSuccess"));

    assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));
    assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));
    assertTrue(chainedListener.testMethodBefore.contains("happyPath"));
    assertTrue(chainedListener.testMethodAfter.contains("happyPath"));
    assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess"));
    assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess"));

    assertTrue(chainedListener.testStarted.contains("happyPath"));
    assertTrue(chainedListener.testSuccess.contains("happyPath"));

    assertTrue(chainedListener.beforeClass.contains("ListenerChainTestCases"));
    assertTrue(chainedListener.afterClass.contains("ListenerChainTestCases"));

    assertTrue(chainedListener.testsBegun.contains("Command line test"));
    assertTrue(chainedListener.testsEnded.contains("Command line test"));

    assertTrue(chainedListener.suiteBegun.contains("Command line suite"));
    assertTrue(chainedListener.suiteEnded.contains("Command line suite"));

    Set<String> expectTests = new HashSet<>(Arrays.asList("method: testSkipped",
                    "method: happyPath", "method: beforeSuccess", "method: beforeSkipped",
                    "method: skipBeforeFailed", "method: skipBeforeSkipped",
                    "method: testAfterSkipped", "method: productTest", "method: failAndPass",
                    "method: afterSuccess", "method: afterFailure",
                    "class: ListenerChainTestCases", "method: testAfterFailed",
                    "method: beforeFailure", "method: afterSkipped", "method: testFailed",
                    "method: testAttachedListeners"));
    Set<String> expectConfigs = new HashSet<>(Arrays.asList("method: afterSuccess",
                    "method: afterFailure", "method: beforeSuccess", "method: beforeFailure",
                    "method: beforeSkipped", "method: afterSkipped"));

    assertEquals(chainedListener.xformTest, expectTests);
    assertEquals(chainedListener.xformConfig, expectConfigs);
    assertTrue(chainedListener.xformProvider.contains("method: dataProvider"));
    assertTrue(chainedListener.xformFactory.contains("method: createInstances"));
    assertTrue(chainedListener.xformListeners.contains("class: ListenerChainTestCases"));

    assertTrue(chainedListener.interceptor.contains("Command line test"));
}
项目:TestNG-Foundation    文件:ListenerChainTest.java   
@Test
public void verifyConstructorFactory(){
    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ConstructorFactory.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.run();

    ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();

    assertEquals(tla.getPassedTests().size(), 3, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");

    assertTrue(chainedListener.testMethodBefore.contains("fakeTest"));
    assertTrue(chainedListener.testMethodAfter.contains("fakeTest"));

    assertTrue(chainedListener.testStarted.contains("fakeTest"));
    assertTrue(chainedListener.testSuccess.contains("fakeTest"));

    assertTrue(chainedListener.beforeClass.contains("ConstructorFactory"));
    assertTrue(chainedListener.afterClass.contains("ConstructorFactory"));

    assertTrue(chainedListener.testsBegun.contains("Command line test"));
    assertTrue(chainedListener.testsEnded.contains("Command line test"));

    assertTrue(chainedListener.suiteBegun.contains("Command line suite"));
    assertTrue(chainedListener.suiteEnded.contains("Command line suite"));

    assertTrue(chainedListener.xformTest.contains("method: fakeTest"));
    assertTrue(chainedListener.xformProvider.contains("method: ints"));
    assertTrue(chainedListener.xformFactory.contains("ctor: (unknown)"));

    assertTrue(chainedListener.interceptor.contains("Command line test"));
}
项目:test-analyzer    文件:TestNgRunResult.java   
public TestNgRunResult(TestListenerAdapter listener) {
    this.m_listener = listener;
}
项目:pinot    文件:HybridClusterIntegrationTestCommandLineRunner.java   
public static void main(String[] args) throws Exception {
  int numArgs = args.length;
  if (!((numArgs == 5) || (numArgs == 6 && args[0].equals("--llc")))) {
    printUsage();
  }

  CustomHybridClusterIntegrationTest._enabled = true;

  int argIdx = 0;
  if (args[0].equals("--llc")) {
    CustomHybridClusterIntegrationTest._useLlc = true;
    argIdx++;
  }

  CustomHybridClusterIntegrationTest._tableName = args[argIdx++];
  File schemaFile = new File(args[argIdx++]);
  Preconditions.checkState(schemaFile.isFile());
  CustomHybridClusterIntegrationTest._schemaFile = schemaFile;
  File dataDir = new File(args[argIdx++]);
  Preconditions.checkState(dataDir.isDirectory());
  CustomHybridClusterIntegrationTest._dataDir = dataDir;
  CustomHybridClusterIntegrationTest._invertedIndexColumns = Arrays.asList(args[argIdx++].split(","));
  CustomHybridClusterIntegrationTest._sortedColumn = args[argIdx];

  TestListenerAdapter testListenerAdapter = new TestListenerAdapter();
  TestNG testNG = new TestNG();
  testNG.setTestClasses(new Class[]{CustomHybridClusterIntegrationTest.class});
  testNG.addListener(testListenerAdapter);
  testNG.run();

  System.out.println(testListenerAdapter.toString());
  boolean success = true;
  List<ITestResult> skippedTests = testListenerAdapter.getSkippedTests();
  if (!skippedTests.isEmpty()) {
    System.out.println("Skipped tests: " + skippedTests);
    for (ITestResult skippedTest : skippedTests) {
      System.out.println(skippedTest.getName() + ": " + skippedTest.getThrowable());
    }
    success = false;
  }
  List<ITestResult> failedTests = testListenerAdapter.getFailedTests();
  if (!failedTests.isEmpty()) {
    System.err.println("Failed tests: " + failedTests);
    for (ITestResult failedTest : failedTests) {
      System.out.println(failedTest.getName() + ": " + failedTest.getThrowable());
    }
    success = false;
  }
  if (success) {
    System.exit(0);
  } else {
    System.exit(1);
  }
}
项目:carina    文件:HealthCheckListener.java   
private void checkHealth(ISuite suite, String className, String[] methods) {

        if (className.isEmpty()) {
            return;
        }

        // create runtime XML suite for health check
        XmlSuite xmlSuite = new XmlSuite();
        xmlSuite.setName("HealthCheck XmlSuite - " + className);

        XmlTest xmltest = new XmlTest(xmlSuite);
        xmltest.setName("HealthCheck TestCase");
        XmlClass healthCheckClass = new XmlClass();
        healthCheckClass.setName(className);

        // TestNG do not execute missed methods so we have to calulate expected methods count to handle potential mistakes in methods naming  
        int expectedMethodsCount = -1; 
        if (methods != null) {
            // declare particular methods if they are provided
            List<XmlInclude> methodsToRun = constructIncludes(methods);
            expectedMethodsCount = methodsToRun.size();
            healthCheckClass.setIncludedMethods(methodsToRun);
        }

        xmltest.setXmlClasses(Arrays.asList(new XmlClass[] { healthCheckClass }));
        xmlSuite.setTests(Arrays.asList(new XmlTest[] { xmltest }));


        LOGGER.info("HealthCheck '" + className + "' is started.");
        LOGGER.debug("HealthCheck suite content:" + xmlSuite.toXml());

        // Second TestNG process to run HealthCheck
        TestNG testng = new TestNG();
        testng.setXmlSuites(Arrays.asList(xmlSuite));

        TestListenerAdapter tla = new TestListenerAdapter();
        testng.addListener(tla);

        testng.run();
        synchronized (this) {
            boolean passed = false;
            if (expectedMethodsCount == -1) {
                if (tla.getPassedTests().size() > 0 && tla.getFailedTests().size() == 0
                        && tla.getSkippedTests().size() == 0) {
                    passed = true;
                }
            } else {
                LOGGER.info("Expected passed tests count: " + expectedMethodsCount);
                if (tla.getPassedTests().size() == expectedMethodsCount && tla.getFailedTests().size() == 0
                        && tla.getSkippedTests().size() == 0) {
                    passed = true;
                }
            }
            if (passed) {
                LOGGER.info("HealthCheck suite '" + className + "' is finished successfully.");
            } else {
                throw new SkipException("Skip test(s) due to health check failures for '" + className + "'");
            }
        }
    }