use of junit.framework.TestResult in project felix by apache.
the class JunitCommand method execute.
/**
* Executes the command.
* @param line the command line
* @param out the output stream
* @param err the error stream
* @see org.apache.felix.shell.Command#execute(java.lang.String, java.io.PrintStream, java.io.PrintStream)
*/
public void execute(String line, PrintStream out, PrintStream err) {
line = line.substring(getName().length()).trim();
List tr = null;
if (line.equals("all")) {
if (m_runner.getTests() == null) {
err.println("No tests to execute");
return;
} else {
out.println("Executing " + getNamesFromTests(m_runner.getTests()));
tr = m_runner.run();
}
} else {
try {
Long bundleId = new Long(line);
if (m_runner.getTests(bundleId.longValue()) == null) {
err.println("No tests to execute");
return;
} else {
out.println("Executing " + getNamesFromTests(m_runner.getTests(bundleId.longValue())));
tr = m_runner.run(bundleId.longValue());
}
} catch (NumberFormatException e) {
err.println("Unable to parse id " + line);
return;
}
}
ListIterator it = tr.listIterator();
while (it.hasNext()) {
TestResult result = (TestResult) it.next();
if (result.failureCount() != 0) {
TestFailure fail = (TestFailure) result.failures().nextElement();
out.println(fail.trace());
return;
}
}
}
use of junit.framework.TestResult in project felix by apache.
the class JunitExtender method run.
/**
* Runs tests.
* @return the list of {@link TestResult}
* @see org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner#run()
*/
public synchronized List run() {
List /*<TestResult>*/
results = new ArrayList(/*<TestResult>*/
m_suites.size());
Iterator /*<Entry<Bundle, List<Class>>>*/
it = m_suites.entrySet().iterator();
while (it.hasNext()) {
Entry /*<Bundle, List<Class>>*/
entry = (Entry) it.next();
Bundle bundle = (Bundle) entry.getKey();
List /*<Class>*/
list = (List) m_suites.get(bundle);
for (int i = 0; i < list.size(); i++) {
Test test = createTestFromClass((Class) list.get(i), bundle);
TestResult tr = doRun(test);
results.add(tr);
}
}
return results;
}
use of junit.framework.TestResult in project android_frameworks_base by crdroidandroid.
the class UiAutomatorTestRunner method start.
/**
* Called after all test classes are in place, ready to test
*/
protected void start() {
TestCaseCollector collector = getTestCaseCollector(this.getClass().getClassLoader());
try {
collector.addTestClasses(mTestClasses);
} catch (ClassNotFoundException e) {
// will be caught by uncaught handler
throw new RuntimeException(e.getMessage(), e);
}
if (mDebug) {
Debug.waitForDebugger();
}
mHandlerThread = new HandlerThread(HANDLER_THREAD_NAME);
mHandlerThread.setDaemon(true);
mHandlerThread.start();
UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper();
automationWrapper.connect();
long startTime = SystemClock.uptimeMillis();
TestResult testRunResult = new TestResult();
ResultReporter resultPrinter;
String outputFormat = mParams.getString("outputFormat");
List<TestCase> testCases = collector.getTestCases();
Bundle testRunOutput = new Bundle();
if ("simple".equals(outputFormat)) {
resultPrinter = new SimpleResultPrinter(System.out, true);
} else {
resultPrinter = new WatcherResultPrinter(testCases.size());
}
try {
automationWrapper.setRunAsMonkey(mMonkey);
mUiDevice = UiDevice.getInstance();
mUiDevice.initialize(new ShellUiAutomatorBridge(automationWrapper.getUiAutomation()));
String traceType = mParams.getString("traceOutputMode");
if (traceType != null) {
Tracer.Mode mode = Tracer.Mode.valueOf(Tracer.Mode.class, traceType);
if (mode == Tracer.Mode.FILE || mode == Tracer.Mode.ALL) {
String filename = mParams.getString("traceLogFilename");
if (filename == null) {
throw new RuntimeException("Name of log file not specified. " + "Please specify it using traceLogFilename parameter");
}
Tracer.getInstance().setOutputFilename(filename);
}
Tracer.getInstance().setOutputMode(mode);
}
// add test listeners
testRunResult.addListener(resultPrinter);
// add all custom listeners
for (TestListener listener : mTestListeners) {
testRunResult.addListener(listener);
}
// run tests for realz!
for (TestCase testCase : testCases) {
prepareTestCase(testCase);
testCase.run(testRunResult);
}
} catch (Throwable t) {
// catch all exceptions so a more verbose error message can be outputted
resultPrinter.printUnexpectedError(t);
testRunOutput.putString("shortMsg", t.getMessage());
} finally {
long runTime = SystemClock.uptimeMillis() - startTime;
resultPrinter.print(testRunResult, runTime, testRunOutput);
automationWrapper.disconnect();
automationWrapper.setRunAsMonkey(false);
mHandlerThread.quit();
}
}
use of junit.framework.TestResult in project bnd by bndtools.
the class Activator method test.
/**
* The main test routine.
*
* @param bundle The bundle under test or null
* @param testnames The names to test
* @param report The report writer or null
* @return # of errors
*/
int test(Bundle bundle, String testnames, Writer report) {
trace("testing bundle %s with %s", bundle, testnames);
Bundle fw = context.getBundle(0);
try {
bundle = findHost(bundle);
List<String> names = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(testnames, " ,");
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (!names.contains(token))
names.add(token);
}
List<TestReporter> reporters = new ArrayList<TestReporter>();
final TestResult result = new TestResult();
Tee systemOut = new Tee(System.err);
Tee systemErr = new Tee(System.err);
systemOut.capture(isTrace()).echo(true);
systemErr.capture(isTrace()).echo(true);
final PrintStream originalOut = System.out;
final PrintStream originalErr = System.err;
System.setOut(systemOut.getStream());
System.setErr(systemErr.getStream());
trace("changed streams");
try {
BasicTestReport basic = new BasicTestReport(this, systemOut, systemErr, result);
add(reporters, result, basic);
if (port > 0) {
add(reporters, result, jUnitEclipseReport);
}
if (report != null) {
add(reporters, result, new JunitXmlReport(report, bundle, basic));
}
for (TestReporter tr : reporters) {
tr.setup(fw, bundle);
}
TestSuite suite = createSuite(bundle, names, result);
try {
trace("created suite %s #%s", suite.getName(), suite.countTestCases());
List<Test> flattened = new ArrayList<Test>();
int realcount = flatten(flattened, suite);
for (TestReporter tr : reporters) {
tr.begin(flattened, realcount);
}
trace("running suite %s", suite);
suite.run(result);
} catch (Throwable t) {
trace("%s", t);
result.addError(suite, t);
} finally {
for (TestReporter tr : reporters) {
tr.end();
}
}
} catch (Throwable t) {
System.err.println("exiting " + t);
t.printStackTrace(System.err);
} finally {
System.setOut(originalOut);
System.setErr(originalErr);
trace("unset streams");
}
System.err.println("Tests run : " + result.runCount());
System.err.println("Passed : " + (result.runCount() - result.errorCount() - result.failureCount()));
System.err.println("Errors : " + result.errorCount());
System.err.println("Failures : " + result.failureCount());
return result.errorCount() + result.failureCount();
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
use of junit.framework.TestResult in project android_frameworks_base by crdroidandroid.
the class TestSuiteBuilderTest method runSuite.
private SuiteExecutionRecorder runSuite(TestSuiteBuilder builder) {
TestSuite suite = builder.build();
SuiteExecutionRecorder recorder = new SuiteExecutionRecorder();
TestResult result = new TestResult();
result.addListener(recorder);
suite.run(result);
return recorder;
}
Aggregations