Add utility to create a TestSuite where a subclass' "FailureExpected" version of a base test is included in the suite, while the base test is excluded

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14371 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Brian Stansberry 2008-02-27 18:06:19 +00:00
parent 0b9123402d
commit 7c0305487f
1 changed files with 45 additions and 0 deletions

View File

@ -23,11 +23,17 @@
*/
package org.hibernate.junit;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
@ -104,4 +110,43 @@ public abstract class UnitTestCase extends junit.framework.TestCase {
protected void reportSkip(String reason, String testDescription) {
SkipLog.LOG.warn( "*** skipping [" + fullTestName() + "] - " + testDescription + " : " + reason, new Exception() );
}
// testsuite utitities ---------------------------------------------------
/**
* Supports easy creation of TestSuites where a subclass' "FailureExpected"
* version of a base test is included in the suite, while the base test
* is excluded. E.g. test class FooTestCase includes method testBar(), while test
* class SubFooTestCase extends FooTestCase includes method testBarFailureExcluded().
* Passing SubFooTestCase.class to this method will return a suite that
* does not include testBar().
*/
public static TestSuite createFailureExpectedSuite(Class testClass) {
TestSuite allTests = new TestSuite(testClass);
Set failureExpected = new HashSet();
Enumeration tests = allTests.tests();
while (tests.hasMoreElements()) {
Test t = (Test) tests.nextElement();
if (t instanceof TestCase) {
String name = ((TestCase) t).getName();
if (name.endsWith("FailureExpected"))
failureExpected.add(name);
}
}
TestSuite result = new TestSuite();
tests = allTests.tests();
while (tests.hasMoreElements()) {
Test t = (Test) tests.nextElement();
if (t instanceof TestCase) {
String name = ((TestCase) t).getName();
if (!failureExpected.contains(name + "FailureExpected")) {
result.addTest(t);
}
}
}
return result;
}
}