All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.experimental.results.PrintableResult Maven / Gradle / Ivy

Go to download

JUnit is a regression testing framework written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java.

There is a newer version: 4.11
Show newest version
package org.junit.experimental.results;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;

import org.junit.internal.TextListener;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

/**
 * A test result that prints nicely in error messages.
 * This is only intended to be used in JUnit self-tests.
 * For example:
 * 
 * 
 *    assertThat(testResult(HasExpectedException.class), isSuccessful());
 * 
*/ public class PrintableResult { /** * The result of running JUnit on {@code type} */ public static PrintableResult testResult(Class type) { return new PrintableResult(type); } private Result result; /** * A result that includes the given {@code failures} */ public PrintableResult(List failures) { this(new FailureList(failures).result()); } private PrintableResult(Result result) { this.result = result; } private PrintableResult(Class type) { this(JUnitCore.runClasses(type)); } @Override public String toString() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); new TextListener(new PrintStream(stream)).testRunFinished(result); return stream.toString(); } /** * Returns the number of failures in this result. */ public int failureCount() { return result.getFailures().size(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy