Java Code Examples for org.testng.ITestResult#SUCCESS_PERCENTAGE_FAILURE

The following examples show how to use org.testng.ITestResult#SUCCESS_PERCENTAGE_FAILURE . 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: 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 2
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 5 votes vote down vote up
private static int getErrors(List<ITestResult> results) {
    int retval = 0;
    for (ITestResult result : results) {
        if (result != null && result.getStatus() != ITestResult.SUCCESS && result.getStatus() != ITestResult.SUCCESS_PERCENTAGE_FAILURE
                && result.getStatus() != ITestResult.FAILURE)
            retval++;
    }
    return retval;
}
 
Example 3
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 5 votes vote down vote up
private static int getErrors(List<ITestResult> results) {
    int retval = 0;
    for (ITestResult result : results) {
        if (result != null && result.getStatus() != ITestResult.SUCCESS && result.getStatus() != ITestResult.SUCCESS_PERCENTAGE_FAILURE
                && result.getStatus() != ITestResult.FAILURE)
            retval++;
    }
    return retval;
}
 
Example 4
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 5
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
public static int getErrors(Collection<TestCase> results) {
    int retval=0;
    for(TestCase result: results) {
        if(result != null && result.status != ITestResult.SUCCESS
          && result.status != ITestResult.SUCCESS_PERCENTAGE_FAILURE
          && result.status != ITestResult.FAILURE)
            retval++;
    }
    return retval;
}
 
Example 6
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 7
Source File: ReporterUtil.java    From qaf with MIT License 4 votes vote down vote up
/**
 * should be called on test method completion
 * 
 * @param context
 * @param result
 */
private static synchronized void updateClassMetaInfo(ITestContext context,
		ITestResult result, String methodfname) {
	String dir = getClassDir(context, result);
	String file = dir + "/meta-info.json";
	FileUtil.checkCreateDir(dir);

	ClassInfo classInfo = getJsonObjectFromFile(file, ClassInfo.class);

	MethodInfo methodInfo = new MethodInfo();
	methodInfo.setStartTime(result.getStartMillis());
	methodInfo.setDuration(result.getEndMillis() - result.getStartMillis());

	if (result.getStatus() == ITestResult.SUCCESS_PERCENTAGE_FAILURE) {
		// methodResult.setPassPer(result.getMethod().getCurrentInvocationCount())
	}
	Map<String, Object> metadata;
	if (result.getMethod().isTest()) {
		methodInfo.setIndex(result.getMethod().getCurrentInvocationCount());
		int retryCount = getBundle().getInt(RetryAnalyzer.RETRY_INVOCATION_COUNT, 0);
		if (retryCount > 0) {
			methodInfo.setRetryCount(retryCount);
		}
		methodInfo.setArgs(result.getParameters());

		if (result.getMethod() instanceof TestNGScenario) {
			TestNGScenario scenario = (TestNGScenario) result.getMethod();
			metadata = scenario.getMetaData();
			metadata.put("description", scenario.getDescription());
			metadata.put("groups", scenario.getGroups());
		} else {
			String desc = ApplicationProperties.CURRENT_TEST_DESCRIPTION
					.getStringVal(result.getMethod().getDescription());
			metadata = new HashMap<String, Object>();
			metadata.put("groups", result.getMethod().getGroups());
			metadata.put("description", desc);
		}
		metadata.put("name", getMethodName(result));
		try {
			metadata.values().removeAll(Collections.singleton(null));
		} catch (Throwable e) {
		}
		methodInfo.setMetaData(metadata);
		getBundle().clearProperty(ApplicationProperties.CURRENT_TEST_DESCRIPTION.key);

		Test test = result.getMethod().getConstructorOrMethod().getMethod()
				.getAnnotation(Test.class);
		if (((test.dependsOnMethods() != null)
				&& (test.dependsOnMethods().length > 0))
				|| ((test.dependsOnGroups() != null)
						&& (test.dependsOnGroups().length > 0))) {
			String[] depends =
					{"Methods: " + Arrays.toString(test.dependsOnMethods()),
							"Groups: " + Arrays.toString(test.dependsOnGroups())};
			methodInfo.setDependsOn(depends);
		}
		methodInfo.setType("test");
	} else { // config method
		String name = getMethodName(result);
		logger.debug("config method:  " + name);

		metadata = new HashMap<String, Object>();
		metadata.put("groups", result.getMethod().getGroups());
		metadata.put("description", result.getMethod().getDescription());
		metadata.put("name", name);

		methodInfo.setMetaData(metadata);
		methodInfo.setType("config");

	}
	methodInfo.setResult(getResult(result.getStatus()));

	if (StringUtil.isNotBlank(methodfname)) {
		metadata.put("resultFileName", methodfname);
	}

	if (!classInfo.getMethods().contains(methodInfo)) {
		logger.debug("method:  result: " + methodInfo.getResult() + " groups: "
				+ methodInfo.getMetaData());
		classInfo.getMethods().add(methodInfo);
		writeJsonObjectToFile(file, classInfo);
	} else {
		logger.warn("methodInfo already wrritten for " + methodInfo.getName());
	}

}
 
Example 8
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 9
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();
        }
    }

}