Java Code Examples for org.testng.ITestResult#SKIP

The following examples show how to use org.testng.ITestResult#SKIP . 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: ExtentTestManager.java    From extentreports-testng-adapter with Apache License 2.0 6 votes vote down vote up
public static synchronized void log(ITestResult result, Boolean createTestAsChild) {
    String msg = "Test ";
    Status status = Status.PASS;
    switch (result.getStatus()) {
        case ITestResult.SKIP:
            status = Status.SKIP;
            msg += "skipped";
            break;
        case ITestResult.FAILURE:
            status = Status.FAIL;
            msg += "failed";
            break;
        default:
            msg += "passed";
            break;
    }
    if (ExtentTestManager.getTest(result) == null) {
        ExtentTestManager.createMethod(result, createTestAsChild);
    }
    if (result.getThrowable() != null) {
        ExtentTestManager.getTest(result).log(status, result.getThrowable());
        return;
    }
    ExtentTestManager.getTest(result).log(status, msg);
}
 
Example 2
Source File: MobileSetupManager.java    From functional-tests-core with Apache License 2.0 6 votes vote down vote up
/**
 * Log test results.
 *
 * @param previousTestStatus Outcome of the test.
 * @param testCase           Test name.
 */
public void logTestResult(int previousTestStatus, String testCase) {
    if (previousTestStatus == ITestResult.SUCCESS) {
        if (this.context.settings.takeScreenShotAfterTest) {
            this.context.log.logScreen(testCase + "_pass", "Screenshot after " + testCase);
        }
        this.log.info("=> Test " + testCase + " passed!");
    } else if (previousTestStatus == ITestResult.FAILURE) {
        if (this.context.device == null) {
            LOGGER_BASE.error("The device is null");
        } else {
            try {
                this.context.device.writeConsoleLogToFile(testCase);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        this.context.log.logScreen(testCase + "_fail", "Screenshot after " + testCase);
        this.context.log.saveXmlTree(testCase + "_VisualTree.xml");
        this.log.error("=> Test " + testCase + " failed!");
    } else if (this.context.lastTestResult == ITestResult.SKIP) {
        this.context.log.logScreen(testCase + "_skip", "Screenshot after " + testCase);
        this.log.error("=> Test " + testCase + " skipped!");
    }
}
 
Example 3
Source File: QAFTestNGListener2.java    From qaf with MIT License 6 votes vote down vote up
@Override
protected void report(ITestResult tr) {
	super.report(tr);
	if(!getBundle().getBoolean("cucumber.run.mode", false)) {
		deployResult(tr);
		if (!getBundle().getBoolean("disable.qaf.testng.reporter", false)) {
			QAFTestBase stb = TestBaseProvider.instance().get();
			final List<CheckpointResultBean> checkpoints = new ArrayList<CheckpointResultBean>(
					stb.getCheckPointResults());

			// pro
			final List<LoggingBean> logs = new ArrayList<LoggingBean>(stb.getLog());
			ITestContext testContext = (ITestContext) tr.getAttribute("context");
			ReporterUtil.createMethodResult(testContext, tr, logs, checkpoints);
		}
	}
	if (tr.getStatus() != ITestResult.SKIP) {
		getBundle().clearProperty(RetryAnalyzer.RETRY_INVOCATION_COUNT);
	}
}
 
Example 4
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 6 votes vote down vote up
protected static void writeTestCase(Writer out, TestCase result) throws IOException {
    long time=result.stop_time - result.start_time;
    // StringBuilder sb=new StringBuilder();
    out.write("\n    <testcase classname=\"" + result.classname);
    out.write("\"  name=\"" + result.name + "\" time=\"" + (time / 1000.0) + "\">");

    switch(result.status) {
        case ITestResult.FAILURE:
            String failure=writeFailure("failure", result.failure_type, result.failure_msg, result.stack_trace);
            if(failure != null)
                out.write(failure);
            break;
        case ITestResult.SKIP:
            failure=writeFailure("error", result.failure_type, result.failure_msg, result.stack_trace);
            if(failure != null)
                out.write(failure);
            break;
    }
    out.write("\n    </testcase>\n");
}
 
Example 5
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
protected static String statusToString(int status) {
    switch(status) {
        case ITestResult.SUCCESS:
        case ITestResult.SUCCESS_PERCENTAGE_FAILURE:
            return "OK";
        case ITestResult.FAILURE: return "FAIL";
        case ITestResult.SKIP:    return "SKIP";
        default:                  return "N/A";
    }
}
 
Example 6
Source File: CustomAutomationLogger.java    From pxf with Apache License 2.0 5 votes vote down vote up
/**
 * alert result of test case to the console in the following format:<br>
 * <test name prefix>...<event message>
 * 
 * @param testResult
 */
private void alertEvent(ITestResult testResult, boolean expectedToFail) {
	String eventMessage = "";
	// put the right event message to eventMessage according to testResult.getStatus()
	switch (testResult.getStatus()) {
		case ITestResult.SUCCESS:
			eventMessage = "OK";
			break;
		case ITestResult.FAILURE:
			// if case expected to fail, sign as "EXPECTED FAILURE"
			if (!expectedToFail) {
				eventMessage = "FAILED";
			} else {
				eventMessage = "EXPECTED FAILURE";
			}
			break;
		case ITestResult.SKIP:
			eventMessage = "SKIPPED";
			break;
		default:
			break;
	}

	// redirect System.out back to original stream
	revertStdoutStream();
	// alert event to console
	System.out.println(getTestNamePrefix(testResult) + "..." + eventMessage);
}
 
Example 7
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
public static int getSkips(Collection<TestCase> results) {
    int retval=0;
    for(TestCase result: results) {
        if(result != null && result.status == ITestResult.SKIP)
            retval++;
    }
    return retval;
}
 
Example 8
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
protected static String getStatus(TestCase tr) {
    switch(tr.status) {
        case ITestResult.SUCCESS:
        case ITestResult.SUCCESS_PERCENTAGE_FAILURE:
            return "OK";
        case ITestResult.FAILURE: return "FAIL";
        case ITestResult.SKIP:    return "SKIP";
        default:                  return "UNKNOWN";
    }
}
 
Example 9
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
protected void addTest(Class<?> clazz, ITestResult result) {
    try {
        TestCase test_case=new TestCase(result.getStatus(), clazz.getName(), getMethodName(result),
                                        result.getStartMillis(), result.getEndMillis());
        switch(result.getStatus()) {
            case ITestResult.FAILURE:
            case ITestResult.SKIP:
                Throwable ex=result.getThrowable();
                if(ex != null) {
                    String failure_type=ex.getClass().getName();
                    String failure_msg=ex.getMessage();
                    String stack_trace=printException(ex);
                    test_case.setFailure(failure_type, failure_msg, stack_trace);
                }
                else
                    test_case.setFailure("exception", "SKIPPED", null);
                break;
        }

        synchronized(this) { // handle concurrent access by different threads, if test methods are run in parallel
            DataOutputStream output=tests.get(clazz);
            test_case.writeTo(output);
        }
    }
    catch(Exception e) {
        error(e.toString());
    }
}
 
Example 10
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 5 votes vote down vote up
private static int getSkips(List<ITestResult> results) {
    int retval = 0;
    for (ITestResult result : results) {
        if (result != null && result.getStatus() == ITestResult.SKIP)
            retval++;
    }
    return retval;
}
 
Example 11
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 5 votes vote down vote up
private static int getSkips(List<ITestResult> results) {
    int retval = 0;
    for (ITestResult result : results) {
        if (result != null && result.getStatus() == ITestResult.SKIP)
            retval++;
    }
    return retval;
}
 
Example 12
Source File: Helpers.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
protected String getStatus(ITestResult result) {
    switch (result.getStatus()) {
        case ITestResult.SUCCESS:
            return "Pass";
        case ITestResult.FAILURE:
            return "Fail";
        case ITestResult.SKIP:
            return "Skip";
        default:
            return "Unknown";
    }
}
 
Example 13
Source File: APITestRunner.java    From frameworkium-bdd with Apache License 2.0 5 votes vote down vote up
private void logResult(ITestResult result) {
    switch (result.getStatus()) {
        case ITestResult.FAILURE:
            logger.error("FAIL  {}", scenarioName.get());
            break;
        case ITestResult.SKIP:
            logger.warn("SKIP  {}", scenarioName.get());
            break;
        case ITestResult.SUCCESS:
            logger.info("PASS  {}", scenarioName.get());
            break;
        default:
            logger.warn("Unexpected result status: {}", result.getStatus());
    }
}
 
Example 14
Source File: UITestRunner.java    From frameworkium-bdd with Apache License 2.0 5 votes vote down vote up
private void logResult(ITestResult result) {
    switch (result.getStatus()) {
        case ITestResult.FAILURE:
            logger.error("FAIL  {}", scenarioName.get());
            break;
        case ITestResult.SKIP:
            logger.warn("SKIP  {}", scenarioName.get());
            break;
        case ITestResult.SUCCESS:
            logger.info("PASS  {}", scenarioName.get());
            break;
        default:
            logger.warn("Unexpected result status: {}", result.getStatus());
    }
}
 
Example 15
Source File: ReporterUtil.java    From qaf with MIT License 5 votes vote down vote up
private static String getResult(int res) {
	switch (res) {
		case ITestResult.SUCCESS :
			return "pass";
		case ITestResult.FAILURE :
			return "fail";
		case ITestResult.SKIP :
			return "skip";
		case ITestResult.SUCCESS_PERCENTAGE_FAILURE :
			return "pass";
		default :
			return "";
	}
}
 
Example 16
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * generate the XML report given what we know from all the test results
 */
protected void generateReport() throws IOException {
    for (Map.Entry<Class, List<ITestResult>> entry : classes.entrySet()) {
        Class clazz = entry.getKey();
        List<ITestResult> results = entry.getValue();

        int num_failures = getFailures(results);
        int num_skips = getSkips(results);
        int num_errors = getErrors(results);
        long total_time = getTotalTime(results);

        String file_name = output_dir + File.separator + "TEST-" + clazz.getName();
        if (suffix != null)
            file_name = file_name + "-" + suffix;
        file_name = file_name + ".xml";
        FileWriter out = new FileWriter(file_name, false); // don't append, overwrite
        try {
            out.write(XML_DEF + "\n");

            out.write("\n<testsuite " + " failures=\"" + num_failures + "\" errors=\"" + num_errors + "\" skips=\"" + num_skips + "\" name=\"" + clazz.getName());
            if (suffix != null)
                out.write(" (" + suffix + ")");
            out.write("\" tests=\"" + results.size() + "\" time=\"" + (total_time / 1000.0) + "\">");

            out.write("\n<properties>");
            Properties props = System.getProperties();

            for (Map.Entry<Object, Object> tmp : props.entrySet()) {
                out.write("\n    <property name=\"" + tmp.getKey() + "\"" + " value=\"" + tmp.getValue() + "\"/>");
            }
            out.write("\n</properties>\n");

            for (ITestResult result : results) {
                if (result == null)
                    continue;
                long time = result.getEndMillis() - result.getStartMillis();
                out.write("\n    <testcase classname=\"" + clazz.getName());
                if (suffix != null)
                    out.write(" (" + suffix + ")");
                out.write("\" name=\"" + result.getMethod().getMethodName() + "\" time=\"" + (time / 1000.0) + "\">");

                Throwable ex = result.getThrowable();

                switch (result.getStatus()) {
                case ITestResult.SUCCESS:
                case ITestResult.SUCCESS_PERCENTAGE_FAILURE:
                    break;
                case ITestResult.FAILURE:
                    writeFailure("failure", result.getMethod().getMethod(), ex, "exception", out);
                    break;
                case ITestResult.SKIP:
                    writeFailure("error", result.getMethod().getMethod(), ex, "SKIPPED", out);
                    break;
                default:
                    writeFailure("error", result.getMethod().getMethod(), ex, "exception", out);
                }

                out.write("\n</testcase>");
            }

            Tuple<ByteArrayOutputStream, ByteArrayOutputStream> stdout = outputs.get(clazz);
            if (stdout != null) {
                ByteArrayOutputStream system_out = stdout.getVal1();
                ByteArrayOutputStream system_err = stdout.getVal2();
                writeOutput(out, system_out.toString(), 1);
                out.write("\n");
                writeOutput(out, system_err.toString(), 2);
            }

            out.write("\n</testsuite>\n");
        } finally {
            out.close();
        }
    }

}
 
Example 17
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * generate the XML report given what we know from all the test results
 */
protected void generateReport() throws IOException {
    for (Map.Entry<Class, List<ITestResult>> entry : classes.entrySet()) {
        Class clazz = entry.getKey();
        List<ITestResult> results = entry.getValue();

        int num_failures = getFailures(results);
        int num_skips = getSkips(results);
        int num_errors = getErrors(results);
        long total_time = getTotalTime(results);

        String file_name = output_dir + File.separator + "TEST-" + clazz.getName();
        if (suffix != null)
            file_name = file_name + "-" + suffix;
        file_name = file_name + ".xml";
        FileWriter out = new FileWriter(file_name, false); // don't append, overwrite
        try {
            out.write(XML_DEF + "\n");

            out.write("\n<testsuite " + " failures=\"" + num_failures + "\" errors=\"" + num_errors + "\" skips=\"" + num_skips + "\" name=\"" + clazz.getName());
            if (suffix != null)
                out.write(" (" + suffix + ")");
            out.write("\" tests=\"" + results.size() + "\" time=\"" + (total_time / 1000.0) + "\">");

            out.write("\n<properties>");
            Properties props = System.getProperties();

            for (Map.Entry<Object, Object> tmp : props.entrySet()) {
                out.write("\n    <property name=\"" + tmp.getKey() + "\"" + " value=\"" + tmp.getValue() + "\"/>");
            }
            out.write("\n</properties>\n");

            for (ITestResult result : results) {
                if (result == null)
                    continue;
                long time = result.getEndMillis() - result.getStartMillis();
                out.write("\n    <testcase classname=\"" + clazz.getName());
                if (suffix != null)
                    out.write(" (" + suffix + ")");
                out.write("\" name=\"" + result.getMethod().getMethodName() + "\" time=\"" + (time / 1000.0) + "\">");

                Throwable ex = result.getThrowable();

                switch (result.getStatus()) {
                case ITestResult.SUCCESS:
                case ITestResult.SUCCESS_PERCENTAGE_FAILURE:
                    break;
                case ITestResult.FAILURE:
                    writeFailure("failure", result.getMethod().getMethod(), ex, "exception", out);
                    break;
                case ITestResult.SKIP:
                    writeFailure("error", result.getMethod().getMethod(), ex, "SKIPPED", out);
                    break;
                default:
                    writeFailure("error", result.getMethod().getMethod(), ex, "exception", out);
                }

                out.write("\n</testcase>");
            }

            Tuple<ByteArrayOutputStream, ByteArrayOutputStream> stdout = outputs.get(clazz);
            if (stdout != null) {
                ByteArrayOutputStream system_out = stdout.getVal1();
                ByteArrayOutputStream system_err = stdout.getVal2();
                writeOutput(out, system_out.toString(), 1);
                out.write("\n");
                writeOutput(out, system_err.toString(), 2);
            }

            out.write("\n</testsuite>\n");
        } finally {
            out.close();
        }
    }

}
 
Example 18
Source File: EarlReporter.java    From teamengine with Apache License 2.0 4 votes vote down vote up
/**
 * Creates EARL statements from the given test results. A test result is
 * described by an Assertion resource. The TestResult and TestCase resources
 * are linked to the Assertion in accord with the EARL schema; the latter is
 * also linked to a TestRequirement.
 * 
 * @param earl
 *            An RDF Model containing EARL statements.
 * @param results
 *            The results of invoking a collection of test methods.
 */
void processTestResults(Model earl, IResultMap results) {
    for (ITestResult tngResult : results.getAllResults()) {
        // create earl:Assertion
        long endTime = tngResult.getEndMillis();
        GregorianCalendar calTime = new GregorianCalendar(TimeZone.getDefault());
        calTime.setTimeInMillis(endTime);
        Resource assertion = earl.createResource("assert-" + ++this.resultCount,
                EARL.Assertion);
        assertion.addProperty(EARL.mode, EARL.AutomaticMode);
        assertion.addProperty(EARL.assertedBy, this.assertor);
        assertion.addProperty(EARL.subject, this.testSubject);
        // link earl:TestResult to earl:Assertion
        Resource earlResult = earl.createResource("result-" + this.resultCount,
                EARL.TestResult);
        earlResult.addProperty(DCTerms.date, earl.createTypedLiteral(calTime));
        switch (tngResult.getStatus()) {
        case ITestResult.FAILURE:
            earlResult.addProperty(DCTerms.description, getDetailMessage(tngResult));
            if (AssertionError.class.isInstance(tngResult.getThrowable())) {
                earlResult.addProperty(EARL.outcome, EARL.Fail);
            } else { // an exception occurred
                earlResult.addProperty(EARL.outcome, EARL.CannotTell);
            }
            processResultAttributes(earlResult, tngResult);
            break;
        case ITestResult.SKIP:
            earlResult.addProperty(DCTerms.description, getDetailMessage(tngResult));
            earlResult.addProperty(EARL.outcome, EARL.NotTested);
            break;
        default:
            earlResult.addProperty(EARL.outcome, EARL.Pass);
            break;
        }
        assertion.addProperty(EARL.result, earlResult);
        // link earl:TestCase to earl:Assertion and earl:TestRequirement
        String testMethodName = tngResult.getMethod().getMethodName();
        String testClassName = tngResult.getTestClass().getName().replaceAll("\\.", "/");
        StringBuilder testCaseId = new StringBuilder(testClassName);
        testCaseId.append('#').append(testMethodName);
        Resource testCase = earl.createResource(testCaseId.toString(), EARL.TestCase);
        testCase.addProperty(DCTerms.title, breakIntoWords(testMethodName));
        String testDescr = tngResult.getMethod().getDescription();
        if (null != testDescr && !testDescr.isEmpty()) {
            testCase.addProperty(DCTerms.description, testDescr);
        }
        assertion.addProperty(EARL.test, testCase);
        String testReqName = tngResult.getTestContext().getName().replaceAll("\\s", "-");
        earl.createResource(testReqName).addProperty(DCTerms.hasPart, testCase);
    }
}
 
Example 19
Source File: SeleniumTestHandler.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
/** Is invoked when test or configuration is finished. */
private void onTestFinish(ITestResult result) {
  // do not treat SeleniumTestHandler error as test failure
  if (testsWithFailure.containsKey(result.getTestClass().getRealClass().getName())
      && testsWithFailure
          .get(result.getTestClass().getRealClass().getName())
          .getMethod()
          .equals(result.getMethod())
      && result.getMethod().getCurrentInvocationCount() == 1) {
    // restore initial test exception
    result.setThrowable(
        testsWithFailure.get(result.getTestClass().getRealClass().getName()).getThrowable());
    return;
  }

  if (result.getStatus() == ITestResult.FAILURE || result.getStatus() == ITestResult.SKIP) {
    switch (result.getStatus()) {
      case ITestResult.FAILURE:
        if (result.getMethod().isTest()) {
          String errorDetails =
              result.getThrowable() != null
                  ? " Error: " + result.getThrowable().getLocalizedMessage()
                  : "";

          LOG.error("Test {} failed.{}", getCompletedTestLabel(result.getMethod()), errorDetails);
          LOG.debug(result.getThrowable().getLocalizedMessage(), result.getThrowable());

          testsWithFailure.put(result.getTestClass().getRealClass().getName(), result);
        }

        captureWebDriver(result);
        captureTestWorkspaceLogs(result);

        break;

      case ITestResult.SKIP:
        String skipReasonDetails =
            result.getThrowable() != null
                ? " The reason: " + result.getThrowable().getLocalizedMessage()
                : "";
        if (result.getMethod().isTest()) {
          LOG.warn(
              "Test {} skipped.{}", getCompletedTestLabel(result.getMethod()), skipReasonDetails);
        }

        // don't capture test data if test is skipped because of previous test with higher
        // priority failed
        if (testsWithFailure.containsKey(result.getMethod().getInstance().getClass().getName())) {
          return;
        }

        break;

      default:
    }
  }
}
 
Example 20
Source File: QAFTestNGListener2.java    From qaf with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void deployResult(ITestResult tr) {
	try {
		if (ResultUpdator.getResultUpdatorsCnt()>0 && (tr.getMethod() instanceof TestNGScenario) && ((tr.getStatus() == ITestResult.FAILURE)
				|| (tr.getStatus() == ITestResult.SUCCESS || tr.getStatus() == ITestResult.SKIP))) {

			TestCaseRunResult.Status status = tr.getStatus() == ITestResult.SUCCESS ? TestCaseRunResult.Status.PASS
					: tr.getStatus() == ITestResult.FAILURE ? TestCaseRunResult.Status.FAIL
							: TestCaseRunResult.Status.SKIPPED;

			TestNGScenario scenario = (TestNGScenario) tr.getMethod();
			Map<String, Object> params = new HashMap<String, Object>(scenario.getMetaData());
			params.put("duration", tr.getEndMillis() - tr.getStartMillis());

			Map<String, Object> executionInfo = new HashMap<String, Object>();
			executionInfo.put("testName", tr.getTestContext().getCurrentXmlTest().getName());
			executionInfo.put("suiteName", tr.getTestContext().getSuite().getName());
			
			Map<String, Object> runPrams = new HashMap<String, Object>(
					tr.getTestContext().getCurrentXmlTest().getAllParameters());
			runPrams.putAll(ConfigurationConverter.getMap(getBundle().subset("env")));
			executionInfo.put("env", runPrams);
			int retryCount = getBundle().getInt(RetryAnalyzer.RETRY_INVOCATION_COUNT, 0);
			boolean willRetry =  getBundle().getBoolean(RetryAnalyzer.WILL_RETRY, false);
			getBundle().clearProperty(RetryAnalyzer.WILL_RETRY);
			if(retryCount>0) {
				executionInfo.put("retryCount", retryCount);
			}
			TestCaseRunResult testCaseRunResult = new TestCaseRunResult(status, scenario.getMetaData(),
					tr.getParameters(), executionInfo, scenario.getSteps(), tr.getStartMillis(),willRetry,scenario.isTest() );
			testCaseRunResult.setClassName(scenario.getClassOrFileName());
			if (scenario.getGroups() != null && scenario.getGroups().length > 0) {
				testCaseRunResult.getMetaData().put("groups", scenario.getGroups());
			}
			testCaseRunResult.getMetaData().put("description",scenario.getDescription());
			testCaseRunResult.setThrowable(tr.getThrowable());
			ResultUpdator.updateResult(testCaseRunResult);
		}
	} catch (Exception e) {
		logger.warn("Unable to deploy result", e);
	}
}