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

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The 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.Request;
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 { private Result result; /** * The result of running JUnit on {@code type} */ public static PrintableResult testResult(Class type) { return testResult(Request.aClass(type)); } /** * The result of running JUnit on Request {@code request} */ public static PrintableResult testResult(Request request) { return new PrintableResult(new JUnitCore().run(request)); } /** * A result that includes the given {@code failures} */ public PrintableResult(List failures) { this(new FailureList(failures).result()); } private PrintableResult(Result result) { this.result = result; } /** * Returns the number of failures in this result. */ public int failureCount() { return result.getFailures().size(); } @Override public String toString() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); new TextListener(new PrintStream(stream)).testRunFinished(result); return stream.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy