junit.extensions.jfunc
Class JFuncSuite
java.lang.Object
|
+--junit.framework.TestSuite
|
+--junit.extensions.jfunc.JFuncSuite
- All Implemented Interfaces:
- junit.framework.Test
- public class JFuncSuite
- extends junit.framework.TestSuite
The JFuncSuite uses dynamic proxies for classes to make
suite construction in JUnit easier and emplore more compile time
checks. This suite will only be useful to you, if you have to
construct your suites by hand. If you simply allow your suites to
be dynamically generated, just keep doing what you've been doing.
Instead of calling something like this:
suite.add(new SimpleTest("testPassed"));
suite.add(new SimpleTest("testFailed"));
suite.add(new SimpleTest("testErrored"));
// can't do this with the current TestCase in Junit
// suite.add(new SimpleTest("testWithArgs", new Object[] { "ugly" }));
return suite;
The new code style will look much more javaish:
SimpleTest tc = (SimpleTest) suite.getTestProxy(new SimpleTest());
tc.testPassed();
tc.testFailed();
tc.testErrored();
// TestProxies can accept arguments
// tc.testWithArgs("pretty");
return suite;
These two pieces of code are effectively the same, except one is
cleaner, easier to read in my opinion and has more checks that
happen at compile time.
Constructor Summary |
JFuncSuite()
Constructs a test suite object. |
Method Summary |
junit.framework.Test |
getTestProxy(junit.framework.Test test)
Returns an object that looks like the given test object, and
can be cast to that object. |
void |
manyTests(boolean many)
|
void |
oneTest(boolean justOne)
This kind of functionality should be used sparingly as the
state of the test object may be important and tests can
interfere with one anothers data. |
Methods inherited from class junit.framework.TestSuite |
addTest, addTestSuite, countTestCases, getName, run, runTest, setName, testAt, testCount, tests, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
JFuncSuite
public JFuncSuite()
- Constructs a test suite object.
oneTest
public void oneTest(boolean justOne)
- This kind of functionality should be used sparingly as the
state of the test object may be important and tests can
interfere with one anothers data. (Read: Don't use it
if you can avoid it.) Many functional testers will have a hard
time avoiding it, so if you're using static member variables,
this is a better solution.
- Parameters:
justOne
- true will use just one instance of the test
(added JFunc behavior). false will have the suite use a new
test for every test (default JUnit behavior).
manyTests
public void manyTests(boolean many)
- Parameters:
many
- true will have the suite use many tests (default JUnit
behavior). false will use just one instance of the test (added JFunc
behavior).
getTestProxy
public junit.framework.Test getTestProxy(junit.framework.Test test)
- Returns an object that looks like the given test object, and
can be cast to that object. This facilitates a better means of
constructing testcases.