Java Code Examples for org.testng.ITestResult#getStartMillis()

The following examples show how to use org.testng.ITestResult#getStartMillis() . 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: TestNGTestResultProcessorAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 8 votes vote down vote up
private void onTestFinished(ITestResult iTestResult, TestResult.ResultType resultType) {
    Object testId;
    TestStartEvent startEvent = null;
    synchronized (lock) {
        testId = tests.remove(iTestResult);
        if (testId == null) {
            // This can happen when a method fails which this method depends on 
            testId = idGenerator.generateId();
            Object parentId = testMethodToSuiteMapping.get(iTestResult.getMethod());
            startEvent = new TestStartEvent(iTestResult.getStartMillis(), parentId);
        }
    }
    if (startEvent != null) {
        // Synthesize a start event
        resultProcessor.started(new DefaultTestMethodDescriptor(testId, iTestResult.getTestClass().getName(), iTestResult.getName()), startEvent);
    }
    if (resultType == TestResult.ResultType.FAILURE) {
        resultProcessor.failure(testId, iTestResult.getThrowable());
    }
    resultProcessor.completed(testId, new TestCompleteEvent(iTestResult.getEndMillis(), resultType));
}
 
Example 2
Source File: TestNGTestResultProcessorAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void onTestFinished(ITestResult iTestResult, TestResult.ResultType resultType) {
    Object testId;
    TestStartEvent startEvent = null;
    synchronized (lock) {
        testId = tests.remove(iTestResult);
        if (testId == null) {
            // This can happen when a method fails which this method depends on 
            testId = idGenerator.generateId();
            Object parentId = testMethodToSuiteMapping.get(iTestResult.getMethod());
            startEvent = new TestStartEvent(iTestResult.getStartMillis(), parentId);
        }
    }
    if (startEvent != null) {
        // Synthesize a start event
        resultProcessor.started(new DefaultTestMethodDescriptor(testId, iTestResult.getTestClass().getName(), iTestResult.getName()), startEvent);
    }
    if (resultType == TestResult.ResultType.FAILURE) {
        resultProcessor.failure(testId, iTestResult.getThrowable());
    }
    resultProcessor.completed(testId, new TestCompleteEvent(iTestResult.getEndMillis(), resultType));
}
 
Example 3
Source File: CustomJUnitReportListener.java    From heat with Apache License 2.0 6 votes vote down vote up
private void setFailedTcAttribute(XMLStringBuffer doc, ITestResult failedTestCase) {
    Properties attributesFailedTestSuites = new Properties();
    String tcName = ((HashMap<String, String>) failedTestCase.getParameters()[0]).get(PROP_TEST_ID);
    attributesFailedTestSuites.setProperty(XMLConstants.ATTR_NAME, tcName);
    long elapsedTimeMillis = failedTestCase.getEndMillis() - failedTestCase.getStartMillis();
    testRunningTotalTime += elapsedTimeMillis;
    Throwable t = failedTestCase.getThrowable();
    doc.push(XMLConstants.TESTCASE, attributesFailedTestSuites);
    if (t != null) {
        attributesFailedTestSuites.setProperty(XMLConstants.ATTR_TYPE, t.getClass().getName());
        String message = t.getMessage();
        if ((message != null) && (message.length() > 0)) {
            attributesFailedTestSuites.setProperty(XMLConstants.ATTR_MESSAGE, encodeAttr(message)); // ENCODE
        }
        doc.push(XMLConstants.FAILURE, attributesFailedTestSuites);
        doc.addCDATA(Utils.stackTrace(t, false)[0]);
        doc.pop();
    } else {
        doc.addEmptyElement(XMLConstants.FAILURE); // THIS IS AN ERROR
    }
    doc.pop();
}
 
Example 4
Source File: TestNGTestResultProcessorAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void onTestFinished(ITestResult iTestResult, TestResult.ResultType resultType) {
    Object testId;
    TestStartEvent startEvent = null;
    synchronized (lock) {
        testId = tests.remove(iTestResult);
        if (testId == null) {
            // This can happen when a method fails which this method depends on 
            testId = idGenerator.generateId();
            Object parentId = testMethodToSuiteMapping.get(iTestResult.getMethod());
            startEvent = new TestStartEvent(iTestResult.getStartMillis(), parentId);
        }
    }
    if (startEvent != null) {
        // Synthesize a start event
        resultProcessor.started(new DefaultTestMethodDescriptor(testId, iTestResult.getTestClass().getName(), iTestResult.getName()), startEvent);
    }
    if (resultType == TestResult.ResultType.FAILURE) {
        resultProcessor.failure(testId, iTestResult.getThrowable());
    }
    resultProcessor.completed(testId, new TestCompleteEvent(iTestResult.getEndMillis(), resultType));
}
 
Example 5
Source File: TestNGTestResultProcessorAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void onTestFinished(ITestResult iTestResult, TestResult.ResultType resultType) {
    Object testId;
    TestStartEvent startEvent = null;
    synchronized (lock) {
        testId = tests.remove(iTestResult);
        if (testId == null) {
            // This can happen when a method fails which this method depends on 
            testId = idGenerator.generateId();
            Object parentId = testMethodToSuiteMapping.get(iTestResult.getMethod());
            startEvent = new TestStartEvent(iTestResult.getStartMillis(), parentId);
        }
    }
    if (startEvent != null) {
        // Synthesize a start event
        resultProcessor.started(new DefaultTestMethodDescriptor(testId, iTestResult.getTestClass().getName(), iTestResult.getName()), startEvent);
    }
    if (resultType == TestResult.ResultType.FAILURE) {
        resultProcessor.failure(testId, iTestResult.getThrowable());
    }
    resultProcessor.completed(testId, new TestCompleteEvent(iTestResult.getEndMillis(), resultType));
}
 
Example 6
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 6 votes vote down vote up
private static long getTotalTime(List<ITestResult> results) {
    long start = 0, stop = 0;
    for (ITestResult result : results) {
        if (result == null)
            continue;
        long tmp_start = result.getStartMillis(), tmp_stop = result.getEndMillis();
        if (start == 0)
            start = tmp_start;
        else {
            start = Math.min(start, tmp_start);
        }

        if (stop == 0)
            stop = tmp_stop;
        else {
            stop = Math.max(stop, tmp_stop);
        }
    }
    return stop - start;
}
 
Example 7
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 6 votes vote down vote up
private static long getTotalTime(List<ITestResult> results) {
    long start = 0, stop = 0;
    for (ITestResult result : results) {
        if (result == null)
            continue;
        long tmp_start = result.getStartMillis(), tmp_stop = result.getEndMillis();
        if (start == 0)
            start = tmp_start;
        else {
            start = Math.min(start, tmp_start);
        }

        if (stop == 0)
            stop = tmp_stop;
        else {
            stop = Math.max(stop, tmp_stop);
        }
    }
    return stop - start;
}
 
Example 8
Source File: TestNGRunner.java    From buck with Apache License 2.0 5 votes vote down vote up
private void recordResult(ITestResult result, ResultType type, Throwable failure) {
  String stdOut = streamToString(rawStdOutBytes);
  String stdErr = streamToString(rawStdErrBytes);

  String className = result.getTestClass().getName();
  String methodName = getTestMethodNameWithParameters(result);

  long runTimeMillis = result.getEndMillis() - result.getStartMillis();
  results.add(
      new TestResult(className, methodName, runTimeMillis, type, failure, stdOut, stdErr));
}
 
Example 9
Source File: BenchmarkTestListener.java    From oxAuth with MIT License 5 votes vote down vote up
@Override
public void onTestSuccess(ITestResult result) {
	final String methodName = result.getMethod().getMethodName();
	final long takes = result.getEndMillis() - result.getStartMillis();

	Long totalTakes;
	Long totalInvoked;
	
	lock.lock();
	try {
		if (methodTakes.containsKey(methodName)) {
			totalTakes = methodTakes.get(methodName);
			totalInvoked = methodInvoked.get(methodName);

			totalTakes += takes;
			totalInvoked++;
		} else {
			methodNames.add(methodName);

			totalTakes = takes;
			totalInvoked = 1L;
		}
		methodTakes.put(methodName, totalTakes);
		methodInvoked.put(methodName, totalInvoked);
	} finally {
		lock.unlock();
	}
}
 
Example 10
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 11
Source File: ConsoleReporter.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Override
public void onTestFailure(ITestResult result) {
	if (testStarted) {
		long testDuration = result.getEndMillis() - result.getStartMillis();
		print("------------------------------------------------------------------------");
		print("[TEST END]: " + result.getName()); 
		print("duration: " + TimeUnit.MILLISECONDS.toSeconds(testDuration) + " seconds");
		print("status: failure");
		print("------------------------------------------------------------------------");
		testStarted = false;
	}
}
 
Example 12
Source File: ConsoleReporter.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Override
public void onTestSuccess(ITestResult result) {
	if (testStarted) {
		long testDuration = result.getEndMillis() - result.getStartMillis();
		print("------------------------------------------------------------------------");
		print("[TEST END]: " + result.getName()); 
		print("duration: " + TimeUnit.MILLISECONDS.toSeconds(testDuration) + " seconds");
		print("status: success");
		print("------------------------------------------------------------------------");
		testStarted = false;
	}
}
 
Example 13
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 14
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 15
Source File: AbstractDifidoReporter.java    From difido-reports with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestStart(ITestResult result) {
	if (!result.getTestClass().getName().equals(testClassName)) {
		testClassName = result.getTestClass().getName();
		startClassScenario(result);
	}
	String testName = result.getName();
	List<String> testParameters = getTestParameters(result);
	if (!testParameters.isEmpty()) {
		StringBuilder sb = new StringBuilder();
		sb.append(testName);
		sb.append("(");
		String tempString = testParameters.toString().replaceFirst("\\[", "");
		sb.append(tempString.substring(0, tempString.length() - 1));
		sb.append(")");
		testName = sb.toString();
	}

	currentTest = new TestNode(index++, testName, executionUid + "-" + index);
	currentTest.setClassName(testClassName);
	final Date date = new Date(result.getStartMillis());
	currentTest.setTimestamp(TIME_FORMAT.format(date));
	currentTest.setDate(DATE_FORMAT.format(date));
	currentClassScenario.addChild(currentTest);
	testDetails = new TestDetails(currentTest.getUid());
	if (result.getMethod().getDescription() != null) {
		currentTest.setDescription(result.getMethod().getDescription());
	}
	addPropertyIfExist("Class", result.getTestClass().getName());
	addPropertyIfExist("Groups", Arrays.toString(result.getMethod().getGroups()));
	int paramCounter = 0;
	for (String paramValue : testParameters) {
		currentTest.addParameter("param" + paramCounter++, paramValue);
	}

	int numOfAppearances = getAndUpdateTestHistory(result.getTestClass().getName() + testName);
	if (numOfAppearances > 0) {
		currentTest.setName(currentTest.getName() + " (" + ++numOfAppearances + ")");
	}
	updateTestDirectory();
	writeExecution(execution);
	flushBufferedElements("Setup");
	writeTestDetails(testDetails);

}
 
Example 16
Source File: CustomisedListener.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public void onTestSuccess(ITestResult arg0) {
    long timeTaken = ((arg0.getEndMillis() - arg0.getStartMillis()));
    LOGGER.info("Tested: " + arg0.getName() + " Time taken:" + timeTaken + " ms");

}
 
Example 17
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);
	}
}