JUB (JUnit test case Builder) |
JUB (JUnit test case Builder) is intended as a JUnit test case generator framework accompanied by a number of IDE specific extensions. These extensions (tools, plug-ins, etc) are to be invoked from within the IDE and must store generated test case code inside source code repository administered by the IDE. Nevertheless, they have to generate the same test case code for a chosen java class regardless of the actual IDE. |
Although there are a few JUnit test case generators available, they are either strictly command prompt or very tightly bound to a specific IDE. One could imagine that it would be greatly beneficial for some developers (contractors, consultants, etc.) to be able to generate the same testing code regardless of externally enforced environment.
Code generation in JUB (JUnit test case Builder) is a bit more extensive than that provided by other generators. It takes into account multiple constructors, and overloaded methods. It attempts to include all necessary import statements and to place correct tested method signatures and exception testing / handling code into test methods' bodies. It also allows generation of test code for protected and default methods (currently only when test case class resides in the same package as tested class).
JUB’s framework foundation is based on Builder pattern (GoF). IDE specific extensions are accomplished by subclassing Builder, Director, (and some of helper / wrapper classes) and adding necessary "front end" classes for each targeted IDE. Of course ;-) JUB is written in java.
Almost all interesting stuff happens between Builder and Director - reading through their methods will quickly give a good idea of what is going on. Going through one set of Builder and Director IDE specific subclasses will help in understanding how other extensions can be implemented. File testgen.properties contains info used to decide on naming and construction of test cases - it is _strongly_ recommended that one reads comments and modifies entries to customize JUB's behavior as required. Of course, the code itself could use a lot of improvement and I would greatly appreciate any comments, suggestions and help.
Release 0.1.2 supports Eclipse (plug-in) and VisualAge for java (application). The jub.zip file available for download contains jub.jar (java source and class files) and plugin.xml (defining / describing Eclipse plug-in ).
To install "JUB plug-in" one must create "net.sourceforge.jub" directory under "plugins" in Eclipse root directory and unzip jub.zip (resulting in 2 files: "jub.jar" and "plugin.xml") into it. Once Eclipse is restarted, "Build JUnit Test Case" entry appears on (right click) popup menu activated (only) over java type (node marked with white C on green background). It should be noted that one or more java types can be selected and that test case classes will be generated for all top level classes.
To get JUB working inside VAj one must create a new project (e.g., JUB) and import there source code files from jub.jar (one of two files in jub.zip). Adding "IBM IDE utility class libraries" project from VAj repository to the workspace will clear all relevant errors. JUB functionality can be accessed by running net.source.jub.vaj.VATestCaseRunner. Its main method takes "-class" / "-package" / "-project" arguments and triggers class / package / project selection dialog accordingly. Additionally, "-package" and "-project" can be associated with "-exclude" argument indicating that subclasses of "junit.framework.TestCase" and classes named "AllTests" should not have corresponding test cases generated. It is probably most convenient to add all projects loaded in the workspace (JUnit should be among them) to "Project path" and it is necessary to add "IBM IDE Utility local implementation" under "ide\project_resources" in VAj root directory to "Extra directories path" of VATestCaseRunner's "Run main with..." .
In general, future plans include new extensions for other IDEs (Forte, JBuilder, WebGain etc.) and for a command prompt / flat file type of setup as well as improvements to JUB's core framework. Since VAj is destined for extinction it does not seem sensible to invest any more time or effort into improvement of JUB's VAj extension. On the other hand, addition of property page for Eclipse extension would greatly improve usability (going into jub.jar to change the testgen.properties entries is rather horrible). In terms of improvements to JUB's framework removing hardwired dependency on properties file in "super" Builder and provision for protected method testing in test case classes residing in packages other than that of a tested class are highest on my priority list. Having written all that, it seems that I will be quite busy in the next little while so any help will be greatly appreciated ;-).