33 import com.sun.javatest.TestRunner;
34 import com.sun.javatest.WorkDirectory;
35 import com.sun.javatest.lib.MultiTest;
36 import com.sun.javatest.util.BackupPolicy;
37 import java.io.IOException;
38 import java.util.Iterator;
39
40 /**
41 *
42 */
43 public class JUnitTestRunner extends TestRunner {
44
45 /** Creates a new instance of JUnitTestRunner */
46 public JUnitTestRunner() {
47 // could create additional constructors to accept args
48 // might be useful if there are more settings that need to be passed
49 // to the MultiTest class. This class is generally constructed
50 // by the corresponding TestSuite class.
51 }
52
53 protected boolean runTests(Iterator testIter) throws InterruptedException {
54 WorkDirectory wd = getWorkDirectory();
55 TestDescription td = null;
56 //for (TestDescription td: testIter) {
57 for (; testIter.hasNext() ;) {
58 td = (TestDescription)(testIter.next());
59 TestResult tr = new TestResult(td);
60 TestResult.Section outSection = tr.createSection("Main");
61
62 notifyStartingTest(tr);
63 Status execStatus = getMultiTest(td).run(getTestArgs(td), outSection.createOutput("stdout"), outSection.createOutput("stderr"));
64 tr.setStatus(execStatus);
65
66 try {
67 if (execStatus.getType() != Status.PASSED || jtrIfPassed)
68 tr.writeResults(wd, backupPolicy);
69 } catch (IOException e) {
70 // ignore it; the test will have an error status already
71 // could log the error using the logging system
72 }
73
74 notifyFinishedTest(tr);
75 } // for
76
77 return false;
78 }
79
80 public BackupPolicy getBackupPolicy() {
81 return backupPolicy;
82 }
83
84 void setClassLoader(ClassLoader loader) {
85 this.loader = loader;
86
87 try {
88 Class c = loader.loadClass("com.sun.javatest.junit.JUnitMultiTest");
89 } catch (ClassNotFoundException e) {
90 e.printStackTrace();
91 }
92 }
93
94 /**
95 * Get the test class that should be used to execute this test.
96 * The default implementation returns a JUnitBareMultiTest or
97 * JUnitAnnotationMultiTest depending on the <tt>junit.finderscantype</tt>
98 * value in the test description.
99 *
100 * Override this method if you wish to return a <tt>JUnitMultiTest</tt> of
101 * your own.
102 *
103 * @see com.sun.javatest.junit.JUnitMultiTest
104 */
105 protected MultiTest getMultiTest(TestDescription td) {
106 String type = td.getParameter("junit.finderscantype");
107 JUnitMultiTest mt = null;
108
|
33 import com.sun.javatest.TestRunner;
34 import com.sun.javatest.WorkDirectory;
35 import com.sun.javatest.lib.MultiTest;
36 import com.sun.javatest.util.BackupPolicy;
37 import java.io.IOException;
38 import java.util.Iterator;
39
40 /**
41 *
42 */
43 public class JUnitTestRunner extends TestRunner {
44
45 /** Creates a new instance of JUnitTestRunner */
46 public JUnitTestRunner() {
47 // could create additional constructors to accept args
48 // might be useful if there are more settings that need to be passed
49 // to the MultiTest class. This class is generally constructed
50 // by the corresponding TestSuite class.
51 }
52
53 protected boolean runTests(Iterator<TestDescription> testIter) throws InterruptedException {
54 WorkDirectory wd = getWorkDirectory();
55 TestDescription td = null;
56 //for (TestDescription td: testIter) {
57 for (; testIter.hasNext() ;) {
58 td = testIter.next();
59 TestResult tr = new TestResult(td);
60 TestResult.Section outSection = tr.createSection("Main");
61
62 notifyStartingTest(tr);
63 Status execStatus = getMultiTest(td).run(getTestArgs(td), outSection.createOutput("stdout"), outSection.createOutput("stderr"));
64 tr.setStatus(execStatus);
65
66 try {
67 if (execStatus.getType() != Status.PASSED || jtrIfPassed)
68 tr.writeResults(wd, backupPolicy);
69 } catch (IOException e) {
70 // ignore it; the test will have an error status already
71 // could log the error using the logging system
72 }
73
74 notifyFinishedTest(tr);
75 } // for
76
77 return false;
78 }
79
80 public BackupPolicy getBackupPolicy() {
81 return backupPolicy;
82 }
83
84 void setClassLoader(ClassLoader loader) {
85 this.loader = loader;
86
87 try {
88 Class<?> c = loader.loadClass("com.sun.javatest.junit.JUnitMultiTest");
89 } catch (ClassNotFoundException e) {
90 e.printStackTrace();
91 }
92 }
93
94 /**
95 * Get the test class that should be used to execute this test.
96 * The default implementation returns a JUnitBareMultiTest or
97 * JUnitAnnotationMultiTest depending on the <tt>junit.finderscantype</tt>
98 * value in the test description.
99 *
100 * Override this method if you wish to return a <tt>JUnitMultiTest</tt> of
101 * your own.
102 *
103 * @see com.sun.javatest.junit.JUnitMultiTest
104 */
105 protected MultiTest getMultiTest(TestDescription td) {
106 String type = td.getParameter("junit.finderscantype");
107 JUnitMultiTest mt = null;
108
|