summaryrefslogtreecommitdiffstats
path: root/junit4/src/test/java/junit/tests/runner/TextRunnerTest.java
diff options
context:
space:
mode:
authorYohann Roussel <yroussel@google.com>2014-03-19 16:25:37 +0100
committerYohann Roussel <yroussel@google.com>2014-03-20 15:13:33 +0100
commit4eceb95409e844fdc33c9c706e1dc307bfd40303 (patch)
treeee9f4f3fc79f757c79081c336bce4f1782c6ccd8 /junit4/src/test/java/junit/tests/runner/TextRunnerTest.java
parent3d2402901b1a6462e2cf47a6fd09711f327961c3 (diff)
downloadtoolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.zip
toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.gz
toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.bz2
Initial Jack import.
Change-Id: I953cf0a520195a7187d791b2885848ad0d5a9b43
Diffstat (limited to 'junit4/src/test/java/junit/tests/runner/TextRunnerTest.java')
-rw-r--r--junit4/src/test/java/junit/tests/runner/TextRunnerTest.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/junit4/src/test/java/junit/tests/runner/TextRunnerTest.java b/junit4/src/test/java/junit/tests/runner/TextRunnerTest.java
new file mode 100644
index 0000000..d7b5941
--- /dev/null
+++ b/junit4/src/test/java/junit/tests/runner/TextRunnerTest.java
@@ -0,0 +1,61 @@
+package junit.tests.runner;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+public class TextRunnerTest extends TestCase {
+
+ public void testFailure() throws Exception {
+ execTest("junit.tests.framework.Failure", false);
+ }
+
+ public void testSuccess() throws Exception {
+ execTest("junit.tests.framework.Success", true);
+ }
+
+ public void testError() throws Exception {
+ execTest("junit.tests.BogusDude", false);
+ }
+
+ void execTest(String testClass, boolean success) throws Exception {
+ String java= System.getProperty("java.home")+File.separator+"bin"+File.separator+"java";
+ String cp= System.getProperty("java.class.path");
+ //use -classpath for JDK 1.1.7 compatibility
+ String [] cmd= { java, "-classpath", cp, "junit.textui.TestRunner", testClass};
+ Process p= Runtime.getRuntime().exec(cmd);
+ InputStream i= p.getInputStream();
+ while((i.read()) != -1)
+ ; //System.out.write(b);
+ assertTrue((p.waitFor() == 0) == success);
+ if (success)
+ assertTrue(p.exitValue() == 0);
+ else
+ assertFalse(p.exitValue() == 0);
+ }
+
+ public void testRunReturnsResult() {
+ PrintStream oldOut= System.out;
+ System.setOut(new PrintStream (
+ new OutputStream() {
+ @Override
+ public void write(int arg0) throws IOException {
+ }
+ }
+ ));
+ try {
+ TestResult result= junit.textui.TestRunner.run(new TestSuite());
+ assertTrue(result.wasSuccessful());
+ } finally {
+ System.setOut(oldOut);
+ }
+ }
+
+
+} \ No newline at end of file