private void onTestFinished(ITestResult iTestResult, TestResult.ResultType resultType) { Object testId; TestStartEvent startEvent = null; synchronized (lock) { testId = testMethodId.remove(iTestResult); if (testId == null) { // This can happen when a method fails which this method depends on testId = idGenerator.generateId(); Object parentId = testMethodParentId.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)); }
private TestMethodResult readMethodResult(Decoder decoder) throws ClassNotFoundException, IOException { long id = decoder.readSmallLong(); String name = decoder.readString(); TestResult.ResultType resultType = TestResult.ResultType.values()[decoder.readSmallInt()]; long duration = decoder.readSmallLong(); long endTime = decoder.readLong(); TestMethodResult methodResult = new TestMethodResult(id, name, resultType, duration, endTime); int failures = decoder.readSmallInt(); for (int i = 0; i < failures; i++) { String exceptionType = decoder.readString(); String message = decoder.readString(); String stackTrace = decoder.readString(); methodResult.addFailure(message, stackTrace, exceptionType); } return methodResult; }
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)); }
@VisibleForTesting Result getTestResult(TestResult testResult) { TestResult.ResultType testResultType = testResult.getResultType(); List<Throwable> exceptions = testResult.getExceptions(); Result result; switch (testResultType) { case SUCCESS: result = Result.success(); break; case SKIPPED: result = Result.skipped(); break; case FAILURE: //noinspection ConstantConditions result = Result.failure(exceptions); break; default: logger.warn("Test result carried unknown result type '{}'. Assuming success", testResultType); result = Result.success(); } return result; }
private void after(TestDescriptor descriptor, TestResult result) { TestLogEvent event = getEvent(result); if (shouldLogEvent(descriptor, event)) { String details = shouldLogExceptions(result) ? exceptionFormatter.format(descriptor, result.getExceptions()) : null; logEvent(descriptor, event, details); } }
private TestLogEvent getEvent(TestResult result) { switch (result.getResultType()) { case SUCCESS: return TestLogEvent.PASSED; case FAILURE: return TestLogEvent.FAILED; case SKIPPED: return TestLogEvent.SKIPPED; default: throw new AssertionError(); } }
@Override public void afterTest(TestDescriptor testDescriptor, TestResult result) { totalTests += result.getTestCount(); failedTests += result.getFailedTestCount(); skippedTests += result.getSkippedTestCount(); progressLogger.progress(summary()); }
@Override public void afterSuite(TestDescriptor suite, TestResult result) { if (suite.getParent() == null) { if (failedTests > 0) { logger.error(TextUtil.getPlatformLineSeparator() + summary()); } progressLogger.completed(); if (result.getResultType() == TestResult.ResultType.FAILURE) { hadFailures = true; } } }
@Override public void completed(TestDescriptorInternal test, TestResult result, TestCompleteEvent completeEvent) { if (test.isComposite()) { testListener.afterSuite(test, result); } else { testListener.afterTest(test, result); } }
public void completed(TestCompleteEvent event) { this.completeEvent = event; resultType = isFailed() ? TestResult.ResultType.FAILURE : event.getResultType() != null ? event.getResultType() : TestResult.ResultType.SUCCESS; if (!test.isComposite()) { testCount = 1; switch (resultType) { case SUCCESS: successfulCount = 1; break; case FAILURE: failedCount = 1; break; } } if (startEvent.getParentId() != null) { TestState parentState = executing.get(startEvent.getParentId()); if (parentState != null) { if (isFailed()) { parentState.failedChild = true; } parentState.testCount += testCount; parentState.successfulCount += successfulCount; parentState.failedCount += failedCount; } } }
private static AbstractTestResult adapt(TestResult result) { TestResult.ResultType resultType = result.getResultType(); switch (resultType) { case SUCCESS: return new DefaultTestSuccessResult(result.getStartTime(), result.getEndTime()); case SKIPPED: return new DefaultTestSkippedResult(result.getStartTime(), result.getEndTime()); case FAILURE: return new DefaultTestFailureResult(result.getStartTime(), result.getEndTime(), convertExceptions(result.getExceptions())); default: throw new IllegalStateException("Unknown test result type: " + resultType); } }
@Override public void completed(TestDescriptorInternal testDescriptor, TestResult testResult, TestCompleteEvent completeEvent) { if (testDescriptor.getParent() == null) { resultCount = resultCount + testResult.getTestCount(); } if (!testDescriptor.isComposite() && testResult.getFailedTestCount() != 0) { failedTests.add(new FailedTest(testDescriptor.getName(), testDescriptor.getClassName(), getTaskPath(testDescriptor))); } }
@Override public void onConfigurationFailure(ITestResult testResult) { synchronized (lock) { if (!failedConfigurations.add(testResult)) { // workaround for bug in TestNG 6.2 (apparently fixed in some 6.3.x): listener is notified twice per event return; } } // Synthesise a test for the broken configuration method TestDescriptorInternal test = new DefaultTestMethodDescriptor(idGenerator.generateId(), testResult.getMethod().getTestClass().getName(), testResult.getMethod().getMethodName()); resultProcessor.started(test, new TestStartEvent(testResult.getStartMillis())); resultProcessor.failure(test.getId(), testResult.getThrowable()); resultProcessor.completed(test.getId(), new TestCompleteEvent(testResult.getEndMillis(), TestResult.ResultType.FAILURE)); }
public TestClassResult add(TestMethodResult methodResult) { if (methodResult.getResultType() == TestResult.ResultType.FAILURE) { failuresCount++; } if(methodResult.getResultType() == TestResult.ResultType.SKIPPED) { skippedCount++; } methodResults.add(methodResult); return this; }
private void writeTests(SimpleXmlWriter writer, Iterable<TestMethodResult> methodResults, String className, long classId) throws IOException { for (TestMethodResult methodResult : methodResults) { writer.startElement("testcase") .attribute("name", methodResult.getName()) .attribute("classname", className) .attribute("time", String.valueOf(methodResult.getDuration() / 1000.0)); if (methodResult.getResultType() == TestResult.ResultType.SKIPPED) { writer.startElement("skipped"); writer.endElement(); } else { for (TestFailure failure : methodResult.getFailures()) { writer.startElement("failure") .attribute("message", failure.getMessage()) .attribute("type", failure.getExceptionType()); writer.characters(failure.getStackTrace()); writer.endElement(); } } if (outputAssociation.equals(TestOutputAssociation.WITH_TESTCASE)) { writer.startElement("system-out"); writeOutputs(writer, classId, methodResult.getId(), TestOutputEvent.Destination.StdOut); writer.endElement(); writer.startElement("system-err"); writeOutputs(writer, classId, methodResult.getId(), TestOutputEvent.Destination.StdErr); writer.endElement(); } writer.endElement(); } }
public TestMethodResult(long id, String name, TestResult.ResultType resultType, long duration, long endTime) { if (id < 1) { throw new IllegalArgumentException("id must be > 0"); } this.id = id; this.name = name; this.resultType = resultType; this.duration = duration; this.endTime = endTime; }
@Override public void testIgnored(Description description) throws Exception { if (methodName(description) == null) { // An @Ignored class, ignore the event. We don't get testIgnored events for each method, so we have // generate them on our own processIgnoredClass(description); return; } TestDescriptorInternal testInternal = descriptor(idGenerator.generateId(), description); resultProcessor.started(testInternal, startEvent()); resultProcessor.completed(testInternal.getId(), new TestCompleteEvent(timeProvider.getCurrentTime(), TestResult.ResultType.SKIPPED)); }
private void handleEvent(Map<String, Object> event) { // Gradle seems to only allow two tiers of tests, so drop the roots if (event.get("parentId") == null) { return; } JovialTestDescriptor descriptor = descriptors.computeIfAbsent((String) event.get("uniqueId"), uniqueId -> { boolean container = (boolean) event.get("container"); JovialTestDescriptor parent = container ? null : descriptors.get((String) event.get("parentId")); return new JovialTestDescriptor(uniqueId, parent, (String) event.get("displayName"), container); }); switch ((String) event.get("type")) { case "dynamicTestRegistered": // do nothing, for now break; case "executionSkipped": testResultProcessor.completed(descriptor.getId(), new TestCompleteEvent(Instant.now().toEpochMilli(), TestResult.ResultType.SKIPPED)); break; case "executionStarted": testResultProcessor.started(descriptor, new TestStartEvent(Instant.now().toEpochMilli(), null)); break; case "executionFinished": boolean success = (boolean) event.get("success"); TestResult.ResultType result = success ? TestResult.ResultType.SUCCESS : TestResult.ResultType.FAILURE; Throwable cause = (Throwable) event.get("throwable"); if (cause != null) { testResultProcessor.failure(descriptor.getId(), cause); } testResultProcessor.completed(descriptor.getId(), new TestCompleteEvent(Instant.now().toEpochMilli(), result)); break; } }
public void onConfigurationFailure(ITestResult testResult) { if (failedConfigurations.put(testResult, true) != null) { // workaround for bug in TestNG 6.2 (apparently fixed in some 6.3.x): listener is notified twice per event return; } // Synthesise a test for the broken configuration method TestDescriptorInternal test = new DefaultTestMethodDescriptor(idGenerator.generateId(), testResult.getMethod().getTestClass().getName(), testResult.getMethod().getMethodName()); resultProcessor.started(test, new TestStartEvent(testResult.getStartMillis())); resultProcessor.failure(test.getId(), testResult.getThrowable()); resultProcessor.completed(test.getId(), new TestCompleteEvent(testResult.getEndMillis(), TestResult.ResultType.FAILURE)); }
public void afterSuite(TestDescriptor suite, TestResult result) { if (suite.getParent() == null) { if (failedTests > 0) { logger.error(TextUtil.getPlatformLineSeparator() + summary()); } progressLogger.completed(); if (result.getResultType() == TestResult.ResultType.FAILURE) { hadFailures = true; } } }
@Override public void afterTest(TestDescriptor testDescriptor, TestResult testResult) { checkNotNull(testDescriptor); checkNotNull(testResult); Result result = getTestResult(testResult); org.gradle.api.tasks.testing.Test testTask = (org.gradle.api.tasks.testing.Test) task; String suiteName = testTask.getName(); long startTime = testResult.getStartTime(); long elapsed = testResult.getEndTime() - startTime; Test test = new Test(testDescriptor.getName(), testDescriptor.getClassName(), suiteName, result, new DateTime(startTime), elapsed); dispatcherSupplier.get().test(test); }