Allows GWTTestCase#getModuleName() to return null to indicate it should be run as a normal JUnit tests case even though it extends GWTTestCase. See the issue for the rationale.
Patch by: bruce
Review by: scottb, amitmanjhi
Issue: 3772
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5617 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/junit/client/GWTTestCase.java b/user/src/com/google/gwt/junit/client/GWTTestCase.java
index ab71cf0..71252c3 100644
--- a/user/src/com/google/gwt/junit/client/GWTTestCase.java
+++ b/user/src/com/google/gwt/junit/client/GWTTestCase.java
@@ -118,7 +118,8 @@
* return the name of a module that will cause the source for that subclass to
* be included.
*
- * @return the fully qualified name of a module
+ * @return the fully qualified name of a module, or <code>null</code> to run
+ * as a non-GWT test case
*/
public abstract String getModuleName();
@@ -220,7 +221,14 @@
throw new IllegalArgumentException("GWTTestCases require a name; \"" + this.toString()
+ "\" has none. Perhaps you used TestSuite.addTest() instead of addTestClass()?");
}
- JUnitShell.runTest(getModuleName(), this, testResult);
+
+ String moduleName = getModuleName();
+ if (moduleName != null) {
+ JUnitShell.runTest(moduleName, this, testResult);
+ } else {
+ // Run as a non-GWT test
+ super.runTest();
+ }
}
/**
diff --git a/user/src/com/google/gwt/junit/tools/GWTTestSuite.java b/user/src/com/google/gwt/junit/tools/GWTTestSuite.java
index f4962cc..b76f540 100644
--- a/user/src/com/google/gwt/junit/tools/GWTTestSuite.java
+++ b/user/src/com/google/gwt/junit/tools/GWTTestSuite.java
@@ -76,22 +76,29 @@
} else {
return getModuleSuiteFor(suite.testAt(0));
}
- } else if (test instanceof GWTTestCase) {
- GWTTestCase gwtTest = (GWTTestCase) test;
- TestSuite suite = moduleSuites.get(gwtTest.getModuleName());
- if (suite == null) {
- suite = new TestSuite(gwtTest.getModuleName() + ".gwt.xml");
- moduleSuites.put(gwtTest.getModuleName(), suite);
- super.addTest(suite);
- }
- return suite;
- } else {
- if (nonGWTTestSuite == null) {
- nonGWTTestSuite = new TestSuite("Non-GWT");
- super.addTest(nonGWTTestSuite);
- }
- return nonGWTTestSuite;
}
+
+ if (test instanceof GWTTestCase) {
+ GWTTestCase gwtTest = (GWTTestCase) test;
+ String moduleName = gwtTest.getModuleName();
+ if (moduleName != null) {
+ TestSuite suite = moduleSuites.get(moduleName);
+ if (suite == null) {
+ suite = new TestSuite(moduleName + ".gwt.xml");
+ moduleSuites.put(moduleName, suite);
+ super.addTest(suite);
+ }
+ return suite;
+ } else {
+ // Fall-through to group with non-GWT tests.
+ }
+ }
+
+ if (nonGWTTestSuite == null) {
+ nonGWTTestSuite = new TestSuite("Non-GWT");
+ super.addTest(nonGWTTestSuite);
+ }
+ return nonGWTTestSuite;
}
/**