Using Cricket Cage In Your Project
- Get the code into a state where you can run the test.
Get your code to the state where it at least sort of works. You'll need to be able to start a test scenario. If your code throws a stack trace, that's fine; Cricket Cage will write a TestCase that assumes the thrown exception is a failure of the TestCase.
- Add a call to buildTestCase()
At your code's exit point, add a call to
This line of code tells Cricket Cage that you're done with the test scenario and want to generate the TestCase. (The line throws Exception, which is from Velocity. Hopefully it will go away some day.) Test that this method is getting called by running your code again. It should do the exact same thing as before, plus it should emit a remarkably dull JUnit TestCase. You can tweak the features of this test case by using command line arguments to get at system properties.
- Extend the Cricket Cage outside() aspect.
Unpack the aspect-source.jar. In that, you'll find the source code for an abstract aspect named net.walend.cricketcage.GeneratesCalls. You should extend this aspect by creating your own sub aspect. In your aspect, fill in the outside() pointcut. Start with
public pointcut outside(): !(call(* net.walend.cricketcage.*.*(..))||get(* net.walend.cricketcage.*.*));
to avoid nabbing the calls that Cricket Cage will use on itself.
- Compile with ajc.
Compile your code, plus GeneratesCalls.java and your extention of GeneratesCalls, using the ajc compiler.
- Generate the TestCase.
Run the test scenario again. Running the scenario should produce a JUnit TestCase that calls the correct code for the test. If it doesn't, modify the outside() pointcut to get rid of the things you don't want in your test, recompile, and rerun the scenario. When the TestCase does what you want, add it to your test suite, sit back and feel smug.
- Clean up and test.
Remove the call to
and unwind any Exception handling in your code. Move your sub aspect of GeneratesCalls out of your source code. If you are not using ajc for your project, switch back to the other compiler. Recompile everything. Make sure your new TestCase performs as expected.
David Walend firstname.lastname@example.org
Home How To To Do Source Forge License David Walend
Copyright (c) 2002 David Walend