Java源码示例:org.gradle.api.tasks.testing.TestResult
示例1
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));
}
示例2
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;
}
示例3
@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;
}
示例4
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));
}
示例5
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;
}
示例6
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));
}
示例7
@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));
}
示例8
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;
}
示例9
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();
}
}
示例10
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;
}
示例11
@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));
}
示例12
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);
}
}
示例13
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();
}
}
示例14
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;
}
}
}
示例15
public TestClassResult add(TestMethodResult methodResult) {
if (methodResult.getResultType() == TestResult.ResultType.FAILURE) {
failuresCount++;
}
if(methodResult.getResultType() == TestResult.ResultType.SKIPPED) {
skippedCount++;
}
methodResults.add(methodResult);
return this;
}
示例16
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;
}
}
}
示例17
@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);
}
示例18
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));
}
示例19
public TestClassResult add(TestMethodResult methodResult) {
if (methodResult.getResultType() == TestResult.ResultType.FAILURE) {
failuresCount++;
}
if(methodResult.getResultType() == TestResult.ResultType.SKIPPED) {
skippedCount++;
}
methodResults.add(methodResult);
return this;
}
示例20
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));
}
示例21
@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));
}
示例22
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;
}
}
}
示例23
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();
}
}
示例24
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;
}
}
}
示例25
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();
}
}
示例26
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;
}
}
}
示例27
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;
}
}
}
示例28
@Override
public void afterTest(TestDescriptor testDescriptor, TestResult result) {
// Include test failure exception stacktrace(s) in test output log.
if (result.getResultType() == TestResult.ResultType.FAILURE) {
if (result.getExceptions().size() > 0) {
String message = formatter.format(testDescriptor, result.getExceptions());
handlerFor(testDescriptor).write(message);
}
}
}
示例29
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));
}
示例30
public TestClassResult add(TestMethodResult methodResult) {
if (methodResult.getResultType() == TestResult.ResultType.FAILURE) {
failuresCount++;
}
if(methodResult.getResultType() == TestResult.ResultType.SKIPPED) {
skippedCount++;
}
methodResults.add(methodResult);
return this;
}