use of junit.framework.Test in project intellij-community by JetBrains.
the class UsefulTestCase method filteredSuite.
@NotNull
public static Test filteredSuite(@RegExp String regexp, @NotNull Test test) {
final Pattern pattern = Pattern.compile(regexp);
final TestSuite testSuite = new TestSuite();
new Processor<Test>() {
@Override
public boolean process(Test test) {
if (test instanceof TestSuite) {
for (int i = 0, len = ((TestSuite) test).testCount(); i < len; i++) {
process(((TestSuite) test).testAt(i));
}
} else if (pattern.matcher(test.toString()).find()) {
testSuite.addTest(test);
}
return false;
}
}.process(test);
return testSuite;
}
use of junit.framework.Test in project jena by apache.
the class ARPTests method main.
public static void main(String[] args) throws IOException {
Test ts = suite();
PrintWriter pw = new PrintWriter(new FileWriter("src/java/test/com/hp/hpl/jena/rdfxml/xmlinput/test/TestPackage.java"));
pw.println("/*");
pw.println(" * Licensed to the Apache Software Foundation (ASF) under one");
pw.println(" * or more contributor license agreements. See the NOTICE file");
pw.println(" * distributed with this work for additional information");
pw.println(" * regarding copyright ownership. The ASF licenses this file");
pw.println(" * to you under the Apache License, Version 2.0 (the");
pw.println(" * \"License\"); you may not use this file except in compliance");
pw.println(" * with the License. You may obtain a copy of the License at");
pw.println(" *");
pw.println(" * http://www.apache.org/licenses/LICENSE-2.0");
pw.println(" *");
pw.println(" * Unless required by applicable law or agreed to in writing, software");
pw.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
pw.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
pw.println(" * See the License for the specific language governing permissions and");
pw.println(" * limitations under the License.");
pw.println(" */");
pw.println();
pw.println("package org.apache.jena.rdfxml.xmlinput.test;");
pw.println("import junit.framework.TestSuite;");
pw.println("import junit.framework.Test;");
pw.println("import org.apache.jena.shared.wg.*;");
pw.println("public class TestPackage{");
pw.println("static public Test suite() {");
String tsname = toJava(ts, pw, "xx");
pw.println("return " + tsname + ";");
pw.println("} }");
pw.println("");
pw.flush();
}
use of junit.framework.Test in project android_frameworks_base by crdroidandroid.
the class UiAutomatorInstrumentationTestRunner method getAndroidTestRunner.
@Override
protected AndroidTestRunner getAndroidTestRunner() {
AndroidTestRunner testRunner = super.getAndroidTestRunner();
testRunner.addTestListener(new TestListener() {
@Override
public void startTest(Test test) {
if (test instanceof UiAutomatorTestCase) {
((UiAutomatorTestCase) test).initialize(getArguments());
}
}
@Override
public void endTest(Test test) {
}
@Override
public void addFailure(Test test, AssertionFailedError e) {
}
@Override
public void addError(Test test, Throwable t) {
}
});
return testRunner;
}
use of junit.framework.Test in project bnd by bndtools.
the class Activator method flatten.
public int flatten(List<Test> list, TestSuite suite) {
int realCount = 0;
for (Enumeration<?> e = suite.tests(); e.hasMoreElements(); ) {
Test test = (Test) e.nextElement();
if (test instanceof JUnit4TestAdapter) {
list.add(test);
for (Test t : ((JUnit4TestAdapter) test).getTests()) {
if (t instanceof TestSuite) {
realCount += flatten(list, (TestSuite) t);
} else {
list.add(t);
realCount++;
}
}
continue;
}
list.add(test);
if (test instanceof TestSuite) {
realCount += flatten(list, (TestSuite) test);
} else {
realCount++;
}
}
return realCount;
}
use of junit.framework.Test 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;
}
Aggregations