aboutsummaryrefslogtreecommitdiffstats
path: root/tests/junit-runner
diff options
context:
space:
mode:
authorOmair Majid <[email protected]>2011-03-31 11:04:37 -0400
committerOmair Majid <[email protected]>2011-03-31 11:04:37 -0400
commite0674c7824b806ef614acb408aca3c3b3efa7c2a (patch)
tree65c9463a06167c863ccb0d1cd6966b90951129e8 /tests/junit-runner
parent2731d2f8b006f2f07c38c90b7260b60eb752c89f (diff)
Add unit tests for the parser
This changeset adds support for JUnit4 tests to icedtea-web. It also adds some parser tests that check that the parser works. make check will now run these tests if JUnit is available. 2011-03-31 Omair Majid <[email protected]> Add unit tests for the parser * Makefile.am: Add TESTS_DIR,TESTS_SRCDIR, NETX_UNIT_TEST_DIR, and NETX_UNIT_TEST_SRCDIR, JUNIT_RUNNER_DIR, JUNIT_RUNNER_SRCDIR, and JUNIT_RUNNER_JAR. Conditionally define RHINO_TESTS and UNIT_TESTS. (clean-local): Use RHINO_TESTS and UNIT_TESTS. (clean-tests): Depend on clean-netx-tests. Delete directory. (junit-runner-source-files.txt, $(JUNIT_RUNNER_JAR)), (next-unit-tests-sources-files.txt stamps/netx-unit-tests-compile.stamp), (run-netx-unit-tests, clean-netx-tests, clean-junit-runner) (clean-netx-unit-tests): New targets. * configure.ac: Add new optional dependency on junit. * tests/junit-runner/CommandLine.java, * tests/junit-runner/LessVerboseTextListener.java, * tests/junit-runner/README, * tests/netx/unit/net/sourceforge/jnlp/ParserBasicTests.java, * tests/netx/unit/net/sourceforge/jnlp/ParserCornerCaseTests.java, * tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXmlTests.java, * tests/netx/unit/net/sourceforge/jnlp/basic.jnlp: New files.
Diffstat (limited to 'tests/junit-runner')
-rw-r--r--tests/junit-runner/CommandLine.java51
-rw-r--r--tests/junit-runner/LessVerboseTextListener.java51
-rw-r--r--tests/junit-runner/README3
3 files changed, 105 insertions, 0 deletions
diff --git a/tests/junit-runner/CommandLine.java b/tests/junit-runner/CommandLine.java
new file mode 100644
index 0000000..96ddc24
--- /dev/null
+++ b/tests/junit-runner/CommandLine.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * Based on code from JUnit
+ *
+ * This file is made available under the terms of the Common Public License
+ * v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.internal.JUnitSystem;
+import org.junit.internal.RealSystem;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+
+public class CommandLine extends JUnitCore {
+
+ public static void main(String... args) {
+ runMainAndExit(new RealSystem(), args);
+ }
+
+ public static void runMainAndExit(JUnitSystem system, String... args) {
+ new CommandLine().runMain(system, args);
+ system.exit(0);
+ }
+
+ @Override
+ public Result runMain(JUnitSystem system, String... args) {
+ List<Class<?>> classes = new ArrayList<Class<?>>();
+ List<Failure> missingClasses = new ArrayList<Failure>();
+ for (String each : args) {
+ try {
+ classes.add(Class.forName(each));
+ } catch (ClassNotFoundException e) {
+ system.out().println("ERROR: Could not find class: " + each);
+ }
+ }
+ RunListener listener = new LessVerboseTextListener(system);
+ addListener(listener);
+ Result result = run(classes.toArray(new Class[0]));
+ for (Failure each : missingClasses) {
+ result.getFailures().add(each);
+ }
+ return result;
+ }
+
+}
diff --git a/tests/junit-runner/LessVerboseTextListener.java b/tests/junit-runner/LessVerboseTextListener.java
new file mode 100644
index 0000000..0470931
--- /dev/null
+++ b/tests/junit-runner/LessVerboseTextListener.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ *
+ * This file is made available under the terms of the Common Public License
+ * v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+import java.io.PrintStream;
+
+import org.junit.internal.JUnitSystem;
+import org.junit.runner.Description;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+
+public class LessVerboseTextListener extends RunListener {
+
+ private PrintStream writer;
+ private boolean testFailed = false;
+
+ public LessVerboseTextListener(JUnitSystem system) {
+ writer= system.out();
+ }
+
+ @Override
+ public void testStarted(Description description) throws Exception {
+ testFailed = false;
+ }
+
+ @Override
+ public void testFailure(Failure failure) {
+ testFailed = true;
+ writer.println("FAILED: " + failure.getTestHeader() + " " + failure.getMessage());
+ }
+
+ @Override
+ public void testFinished(org.junit.runner.Description description) throws Exception {
+ if (!testFailed) {
+ writer.println("Passed: " + description.getClassName() + "." + description.getMethodName());
+ }
+ }
+
+ @Override
+ public void testRunFinished(Result result) throws Exception {
+ int passed = result.getRunCount() - result.getFailureCount() - result.getIgnoreCount();
+ int failed = result.getFailureCount();
+ int ignored = result.getIgnoreCount();
+ writer.println("Test results: passed: " + passed + "; failed: " + failed + "; ignored: " + ignored);
+ }
+
+}
diff --git a/tests/junit-runner/README b/tests/junit-runner/README
new file mode 100644
index 0000000..9c9d40c
--- /dev/null
+++ b/tests/junit-runner/README
@@ -0,0 +1,3 @@
+junit-runner is used to run tests instead of the standard runner
+org.junit.runner.JUnitCore. It provides output similar to that used by JTreg,
+which is useful for automated comparison.