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


Java ITestResult.getTestContext方法代碼示例

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


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

示例1: 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

示例2: onTestFailure

import org.testng.ITestResult; //導入方法依賴的package包/類
/**
 * This method is useful to print the output console log in case of test failed.
 * We are assuming that we put in the context an attribute whose name is the complete test case ID (example: TEST_SUITE.001) and whose value is
 * 'PASSED' or 'SKIPPED' or 'FAILED'.
 * @param tr test case result - testNG handling
 */
@Override
public void onTestFailure(ITestResult tr) {
    if (tr.getParameters().length > 0) {
        Map<String, String> paramMap = (HashMap<String, String>) tr.getParameters()[0];
        ITestContext testContext = tr.getTestContext();
        //testCaseCompleteID - Example: TEST_SUITE.001
        String testCaseCompleteID = testContext.getName() + TestBaseRunner.TESTCASE_ID_SEPARATOR + testContext.getAttribute(TestBaseRunner.ATTR_TESTCASE_ID);
        logger.error("[{}][{}][{}] -- FAILED", testCaseCompleteID,
                    testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(),
                    testContext.getAttribute(TestBaseRunner.TC_DESCRIPTION_CTX_ATTR).toString());

        if (testContext.getAttribute("failedTestCases") == null) {
            failedTc = new ArrayList<>();
        } else {
            failedTc = (List<ITestResult>) testContext.getAttribute("failedTestCases");
        }
        failedTc.add(tr);
        testContext.setAttribute("failedTestCases", failedTc);

    } else {
        super.onTestFailure(tr);
    }
}
 
開發者ID:HotelsDotCom,項目名稱:heat,代碼行數:30,代碼來源:CustomTestNgListener.java

示例3: onTestSuccess

import org.testng.ITestResult; //導入方法依賴的package包/類
/**
 * This method is useful to print the output console log in case of test success or test skipped.
 * We are assuming that we put in the context an attribute whose name is the complete test case ID (example: TEST_SUITE.001) and whose value is
 * 'PASSED' or 'SKIPPED' or 'FAILED'.
 * @param tr test case result - testNG handling
 */
@Override
public void onTestSuccess(ITestResult tr) {
    if (tr.getParameters().length > 0) {
        Map<String, String> paramMap = (HashMap<String, String>) tr.getParameters()[0];
        ITestContext testContext = tr.getTestContext();
        //testCaseCompleteID - Example: TEST_SUITE.001
        String testCaseCompleteID = testContext.getName() + TestBaseRunner.TESTCASE_ID_SEPARATOR + testContext.getAttribute(TestBaseRunner.ATTR_TESTCASE_ID);
        if (testContext.getAttributeNames().contains(testCaseCompleteID)
                && TestBaseRunner.STATUS_SKIPPED.equals(testContext.getAttribute(testCaseCompleteID))) {
            logger.trace("[{}][{}][{}] -- SKIPPED", testCaseCompleteID,
                    testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(),
                    testContext.getAttribute(TestBaseRunner.TC_DESCRIPTION_CTX_ATTR).toString());

            if (testContext.getAttribute("skippedTestCases") == null) {
                skippedTc = new ArrayList<>();
            } else {
                skippedTc = (List<ITestResult>) testContext.getAttribute("skippedTestCases");
            }
            skippedTc.add(tr);
            testContext.setAttribute("skippedTestCases", skippedTc);

        } else {
            logger.info("[{}][{}][{}] -- PASSED", testCaseCompleteID,
                    testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(),
                    testContext.getAttribute(TestBaseRunner.TC_DESCRIPTION_CTX_ATTR).toString());

            if (testContext.getAttribute("passedTestCases") == null) {
                passedTc = new ArrayList<>();
            } else {
                passedTc = (List<ITestResult>) testContext.getAttribute("passedTestCases");
            }
            passedTc.add(tr);
            testContext.setAttribute("passedTestCases", passedTc);

        }
    } else {
        super.onTestSuccess(tr);
    }
}
 
開發者ID:HotelsDotCom,項目名稱:heat,代碼行數:46,代碼來源:CustomTestNgListener.java

示例4: getCollectionPath

import org.testng.ITestResult; //導入方法依賴的package包/類
/**
 * Get path of directory at which to store artifacts.
 * 
 * @param result TestNG test result object
 * @return path of artifact storage directory
 */
private Path getCollectionPath(ITestResult result) {
    ITestContext testContext = result.getTestContext();
    String outputDirectory = testContext.getOutputDirectory();
    Path collectionPath = Paths.get(outputDirectory);
    return collectionPath.resolve(provider.getArtifactPath(result));
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:13,代碼來源:ArtifactCollector.java


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