當前位置: 首頁>>代碼示例>>Java>>正文


Java ITestResult類代碼示例

本文整理匯總了Java中org.testng.ITestResult的典型用法代碼示例。如果您正苦於以下問題:Java ITestResult類的具體用法?Java ITestResult怎麽用?Java ITestResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ITestResult類屬於org.testng包,在下文中一共展示了ITestResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dependencyError

import org.testng.ITestResult; //導入依賴的package包/類
private boolean dependencyError( ITestResult testResult ) {

        String[] dependentMethods = testResult.getMethod().getMethodsDependedUpon();
        List<ITestResult> failedTests = getFailedTests();
        for (String dependentMethod : dependentMethods) {
            for (ITestResult failedTestResult : failedTests) {
                String failedMethodName = new StringBuilder().append(failedTestResult.getTestClass()
                                                                                     .getName())
                                                             .append(".")
                                                             .append(failedTestResult.getName())
                                                             .toString();
                if (failedMethodName.equals(dependentMethod)) {
                    logger.error("Dependent method '" + dependentMethod + "' failed!",
                                 failedTestResult.getThrowable());
                    return true;
                }
            }
        }

        return false;
    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:22,代碼來源:AtsTestngTestListener.java

示例2: run

import org.testng.ITestResult; //導入依賴的package包/類
/**
 * 測試方法攔截器、所有測試方法在執行開始、執行中、執行完成都會在此方法中完成
 * @param callBack
 * @param testResult
 */
@Override
public void run(IHookCallBack callBack, ITestResult testResult) {
    // 如果測試方法上有@Ignore注解,則跳過測試框架直接執行測試方法
    if (isIgnoreAnnotation(getTestMethod(testResult))) {
        callBack.runTestMethod(testResult);
    }
}
 
開發者ID:DreamYa0,項目名稱:zeratul,代碼行數:13,代碼來源:AbstractDubbo.java

示例3: onTestSkipped

import org.testng.ITestResult; //導入依賴的package包/類
/**
 * [ITestListener]
 * Invoked each time a test is skipped.
 *
 * @param result {@code ITestResult} containing information about the run test
 * @see ITestResult#SKIP
 */
@Override
public void onTestSkipped(ITestResult result) {
    
    // >>>>> ENTER workaround for TestNG bug
    // https://github.com/cbeust/testng/issues/1602
    ITestContext context = result.getTestContext();
    IInvokedMethod method = new InvokedMethod(
                    result.getTestClass(), result.getMethod(), System.currentTimeMillis(), result);
    
    beforeInvocation(method, result, context);
    // <<<<< LEAVE workaround for TestNG bug
    
    synchronized (testListeners) {
        for (ITestListener testListener : testListeners) {
            testListener.onTestSkipped(result);
        }
    }
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:26,代碼來源:ListenerChain.java

示例4: nullObjectsDataSuppliersShouldWork

import org.testng.ITestResult; //導入依賴的package包/類
@Test
public void nullObjectsDataSuppliersShouldWork() {
    final InvokedMethodNameListener listener = run(NullObjectsDataSupplierTests.class);

    assertThat(listener.getSkippedBeforeInvocationMethodNames())
            .hasSize(5)
            .containsExactly(
                    "supplyExtractedNullObject()",
                    "supplyNullArrayData()",
                    "supplyNullCollectionData()",
                    "supplyNullObjectData()",
                    "supplyNullStreamData()"
            );

    assertThat(EntryStream.of(listener.getResults()).values().toList())
            .extracting(ITestResult::getThrowable)
            .extracting(Throwable::getMessage)
            .containsExactly(
                    "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyNullCollectionData.",
                    "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyNullStreamData.",
                    "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyExtractedNullObject.",
                    "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyNullArrayData.",
                    "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyNullObjectData."
            );
}
 
開發者ID:sskorol,項目名稱:test-data-supplier,代碼行數:26,代碼來源:DataSupplierTests.java

示例5: afterInvocation

import org.testng.ITestResult; //導入依賴的package包/類
@Override
public void afterInvocation(final IInvokedMethod method, final ITestResult testResult) {
    if (method.isTestMethod() && testResult.getStatus() == SUCCESS) {
        try {
            getSoftAssert().assertAll();
        } catch (AssertionError e) {
            testResult.getTestContext().getPassedTests().removeResult(testResult.getMethod());
            testResult.setStatus(TestResult.FAILURE);
            testResult.setThrowable(e);
        }
        THREAD_LOCAL_CONTAINER_FOR_SOFT_ASSERTIONS.remove();
    }
}
 
開發者ID:sskorol,項目名稱:qaa-amazon,代碼行數:14,代碼來源:SoftAssertListener.java

示例6: set

import org.testng.ITestResult; //導入依賴的package包/類
/**
 * Store the specified object in the attributes collection.
 * 
 * @param obj object to be stored; 'null' to discard value
 * @return (optional) specified object
 */
private <T> Optional<T> set(T obj) {
    ITestResult result = Reporter.getCurrentTestResult();
    Optional<T> val = TestBase.optionalOf(obj);
    result.setAttribute(key, val);
    return val;
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:13,代碼來源:TestNgBase.java

示例7: endTestcaseWithSuccessStatus

import org.testng.ITestResult; //導入依賴的package包/類
private void endTestcaseWithSuccessStatus( ITestResult testResult ) {

        sendTestEndEventToAgents();
        boolean shouldTestFail = TestcaseStateEventsDispacher.getInstance().hasAnyQueueFailed();
        if (shouldTestFail) {
            logger.warn("At least one queue in test failed");
            testResult.setStatus(ITestResult.FAILURE);
            endTestcaseWithFailureStatus(testResult);
            return;
        }
        logger.info(MSG__TEST_PASSED);

        try {

            currentTestcaseName = null;
            lastTestcaseResult = TestCaseResult.PASSED.toInt();
            // end test case
            logger.endTestcase(TestCaseResult.PASSED);
        } catch (Exception e) {
            logger.fatal("UNEXPECTED EXCEPTION IN [email protected]", e);
        }

    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:24,代碼來源:AtsTestngListener.java

示例8: getFailedTestScreenshotPath

import org.testng.ITestResult; //導入依賴的package包/類
public String getFailedTestScreenshotPath(final String testName, final String methodName)
{
    Iterator<ITestResult> it2 = getMethodResults(testName, methodName).iterator();
    List<String> reporterOutput = new ArrayList<String>();

    String screenshotFileLink = "";

    while (it2.hasNext())
    {
        ITestResult result = it2.next();

        reporterOutput = Reporter.getOutput(result);
        break;
    }

    for (String line : reporterOutput)
    {
        if (line.contains("[Console Log] Screenshot saved in"))
        {
            screenshotFileLink = line.substring(line.indexOf("in") + 3, line.length());
            break;
        }
    }

    return screenshotFileLink;
}
 
開發者ID:pradeeptaswain,項目名稱:oldmonk,代碼行數:27,代碼來源:ReporterAPI.java

示例9: retry

import org.testng.ITestResult; //導入依賴的package包/類
@Override
public boolean retry(final ITestResult result)
{
    try
    {
        config = ProjectConfigurator.initializeProjectConfigurationsFromFile("project.properties");
    } catch (IOException e)
    {
        e.printStackTrace();
    }

    int maxRetryCount = Integer.parseInt(config.getProperty("max.retry.count"));

    if (retryCount <= maxRetryCount)
    {
        LOGGER.info("Retry: " + retryCount + ", Rerunning Failed Test: " + result.getTestClass().getName());
        retryCount++;

        return true;
    }

    return false;
}
 
開發者ID:pradeeptaswain,項目名稱:oldmonk,代碼行數:24,代碼來源:Retry.java

示例10: verifyCanNotCapture

import org.testng.ITestResult; //導入依賴的package包/類
@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");
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:25,代碼來源:ArtifactCollectorTest.java

示例11: getParameters

import org.testng.ITestResult; //導入依賴的package包/類
private List<Parameter> getParameters(final ITestResult testResult) {
    final Stream<Parameter> tagsParameters = testResult.getTestContext()
            .getCurrentXmlTest().getAllParameters().entrySet()
            .stream()
            .map(entry -> new Parameter().withName(entry.getKey()).withValue(entry.getValue()));
    final String[] parameterNames = Optional.of(testResult)
            .map(ITestResult::getMethod)
            .map(ITestNGMethod::getConstructorOrMethod)
            .map(ConstructorOrMethod::getMethod)
            .map(Executable::getParameters)
            .map(Stream::of)
            .orElseGet(Stream::empty)
            .map(java.lang.reflect.Parameter::getName)
            .toArray(String[]::new);
    final String[] parameterValues = Stream.of(testResult.getParameters())
            .map(this::convertParameterValueToString)
            .toArray(String[]::new);
    final Stream<Parameter> methodParameters = range(0, min(parameterNames.length, parameterValues.length))
            .mapToObj(i -> new Parameter().withName(parameterNames[i]).withValue(parameterValues[i]));
    return Stream.concat(tagsParameters, methodParameters)
            .collect(Collectors.toList());
}
 
開發者ID:allure-framework,項目名稱:allure-java,代碼行數:23,代碼來源:AllureTestNg.java

示例12: onTestSuccess

import org.testng.ITestResult; //導入依賴的package包/類
@Override
public void onTestSuccess( ITestResult testResult ) {

    sendTestEndEventToAgents();
    boolean shouldTestFail = TestcaseStateEventsDispacher.getInstance().hasAnyQueueFailed();
    if (shouldTestFail) {
        logger.warn("At least one queue in test failed");
        testResult.setStatus(ITestResult.FAILURE);
        onTestFailure(testResult);
        return;
    }
    logger.info(MSG__TEST_PASSED);

    try {
        // end test case
        logger.endTestcase(TestCaseResult.PASSED);
    } catch (Exception e) {
        logger.fatal("UNEXPECTED EXCEPTION IN [email protected]", e);
    }
    super.onTestSuccess(testResult);
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:22,代碼來源:AtsTestngTestListener.java

示例13: verifyHappyPath

import org.testng.ITestResult; //導入依賴的package包/類
@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");
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:25,代碼來源:ArtifactCollectorTest.java

示例14: getMethodExecutionTime

import org.testng.ITestResult; //導入依賴的package包/類
public Long getMethodExecutionTime(String testName, String methodName)
{
    long startTime = Long.MAX_VALUE;
    long endTime = Long.MIN_VALUE;

    Iterator<ITestResult> it2 = getMethodResults(testName, methodName).iterator();

    while (it2.hasNext())
    {
        ITestResult result = it2.next();

        startTime = result.getStartMillis();
        endTime = result.getEndMillis();

        break;
    }

    return (endTime - startTime);
}
 
開發者ID:pradeeptaswain,項目名稱:oldmonk,代碼行數:20,代碼來源:ReporterAPI.java

示例15: endTestcaseWithFailureStatus

import org.testng.ITestResult; //導入依賴的package包/類
private void endTestcaseWithFailureStatus( ITestResult testResult ) {

        try {
            //Check if the test was successfully started, if not - make it started and then end it with failure
            String testName = testResult.getMethod().toString();
            if (!testName.equals(currentTestcaseName)) {
                startTestcase(testResult);
            }

            sendTestEndEventToAgents();

            // if this is an assertion error, we need to log it
            Throwable failureException = testResult.getThrowable();
            if (failureException instanceof AssertionError) {
                if (failureException.getMessage() != null) {
                    logger.error(ExceptionUtils.getExceptionMsg(failureException));
                } else {
                    logger.error("Received java.lang.AssertionError with null message");
                }
            } else {
                logger.error(MSG__TEST_FAILED, testResult.getThrowable());
            }

            currentTestcaseName = null;
            lastTestcaseResult = TestCaseResult.FAILED.toInt();
            // end test case
            logger.endTestcase(TestCaseResult.FAILED);
        } catch (Exception e) {
            logger.fatal("UNEXPECTED EXCEPTION IN [email protected]", e);
        }

    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:33,代碼來源:AtsTestngListener.java


注:本文中的org.testng.ITestResult類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。