1 33 34 package edu.rice.cs.drjava.model.junit; 35 36 import java.io.PrintStream ; 37 38 import junit.runner.*; 39 import junit.framework.*; 40 import junit.textui.TestRunner; 41 42 45 public class JUnitTestRunner extends TestRunner { 46 47 48 private JUnitModelCallback _jmc; 49 50 51 private PrintStream _writer; 52 53 54 private TestSuiteLoader _classLoader; 55 56 57 private TestResult _result; 58 59 60 private int _errorCount; 61 62 63 private int _failureCount; 64 65 66 public JUnitTestRunner(JUnitModelCallback jmc) { 67 super(); 68 _jmc = jmc; 69 _classLoader = new DrJavaTestSuiteLoader(jmc); 70 _writer = new PrintStream (System.out) { 71 public void print(String s) { } 72 public void println(String s) { } 73 public void println() { } 74 }; 75 76 _errorCount = 0; 77 _failureCount = 0; 78 } 79 80 public synchronized TestResult doRun(Test suite) { 81 _errorCount = 0; 83 _failureCount = 0; 84 85 _result = createTestResult(); 87 _result.addListener(this); 88 _jmc.testSuiteStarted(suite.countTestCases()); 89 suite.run(_result); 91 return _result; 95 } 96 97 98 public TestSuiteLoader getLoader() { return _classLoader; } 99 100 101 protected PrintStream getWriter() { return _writer; } 102 103 protected PrintStream writer() { return getWriter(); } 104 105 106 public synchronized void startTest(Test test) { _jmc.testStarted(test.toString()); } 107 108 109 public synchronized void endTest(Test test) { 110 boolean error = false; 111 boolean failure = false; 112 if (_result.errorCount() > _errorCount) { 113 error = true; 114 _errorCount++; 115 } 116 if (_result.failureCount() > _failureCount) { 117 failure = true; 118 _failureCount++; 119 } 120 boolean success = ! (failure || error); 121 _jmc.testEnded(test.toString(), success, failure); 122 } 123 } 124 | Popular Tags |