CVS: junit/src JUnitTestCase.java,NONE,1.1

David Saff <[email protected]> Mon, 09 Jul 2007 12:38:32 -0700
Newsgroups gmane.comp.java.junit.devel
Message-ID <[email protected]>
Update of /cvsroot/junit/junit/src
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18825/src

Added Files:
	JUnitTestCase.java 
Log Message:
Checked in new tests to clarify behavior of JUnit4TestAdaptor in the presence of @Ignore'd tests and suite() methods, in response to bug 1700187

--- NEW FILE: JUnitTestCase.java ---
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

/**
 * Correct structure:
 *
 * JUnitTestCase
 *  |
 *  |- JUnitTestCase.MyTestSuite
 *  |   |
 *  |   |- JUnitTestCase.MyTestSuite.MyTestCase
 *  |       |
 *  |       |- test1
 *  |       |
 *  |       |- test2
 *  |
 *  |- JUnitTestCase.StopTest
 *      |
 *      |- testStop
 *
 * Wrong structure when test.MyTestSuite is created using JUnit4TestAdapter
 *
 * JUnitTestCase
 *  |
 *  |- JUnitTestCase.MyTestSuite
 *  |   |
 *  |   |- JUnitTestCase.MyTestSuite.MyTestCase
 *  |   |   |
 *  |   |   |- test1
 *  |   |   |
 *  |   |   |- test2
 *  |   |
 *  x   |- JUnitTestCase.StopTest
 *      |
 *      |- testStop
 */
public final class JUnitTestCase
{
	public static void buildUserTests(TestSuite suite)
	{
		// Cause a problem because there are 2 tests
		suite.addTest(new JUnit4TestAdapter(MyTestSuite.class));

		// This works with 2 tests or more
//		suite.addTest(MyTestSuite.suite());
	}

	public static Test suite()
	{
		TestSuite suite = new TestSuite(JUnitTestCase.class.getName());
		buildUserTests(suite);
		suite.addTest(new TestSuite(StopTest.class));
		return suite;
	}

	public static class MyTestCase
	{
		@org.junit.Test
		public void test1()
		{
		}

		@org.junit.Test
		public void test2()
		{
		}
	}

	@SuiteClasses
	({
		MyTestCase.class,
	})
	@RunWith(Suite.class)
	public static class MyTestSuite
	{
		public static Test suite()
		{
			TestSuite suite = new TestSuite(MyTestSuite.class.getName());
			suite.addTest(new JUnit4TestAdapter(MyTestCase.class));
			return suite;
		}
	}

	public static class StopTest extends TestCase
	{
		public void testStop() throws Exception
		{
		}
	}
}


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/