The Mirror plugin generates JUnit test skeletons.
It monitors changes to the source tree (file and directory
additions, deletions, renames and moves), and makes sympathetic
changes (builds test skeletons) under a mirror directory which you specify.
The files in the mirror directory are created using Velocity templates.
You have complete control over what the Velocity templates generate,
but the original intention was to somehow automate the creation
of JUnit test skeletons. Yeah, I know, you should generate your tests
before you start coding, but I'm lazy and forgetful.
Sample Velocity templates provided are called:
- mirror_java.vm - To create a JUnit test skeleton for any java files in your source path.
- mirror_master.vm - To create a JUnit package test skeleton for each directory in your source path.
- dump_variables.vm - To list all the Velocity variables that you can use in your Velocity templates.
If you need to mirror files other than java files, for example, txt files, then you can create a Velocity template called mirror_txt.vm. If no template is found for a file extension, then no mirror file can be created. You get the idea.
- 22 Oct 2002 User can specify the mirror output directory.
- 11 Oct 2002 Fixed NPE loading icon.
- 04 Oct 2002 Idea now ships with JDOM 1.0 beta 7 instead of beta 8, so I had to remove a 1.0 beta 8 "getAttributeValue(String,String)" method invocation.
- 26 Sep 2002 Minor template changes for JUnit 3.8.1
- 06 Sep 2002 Added a configuration panel (accessed via File/Project Properties/MirrorPlugin). Velocity variables can now be added/deleted/edited interactively. The variables are stored using 'var' elements in your project file. You can define either simple strings, or you can specify the name of a class to be instantiated. This way, you can customize the variables available in your Velocity templates without having to modify the Mirror plugin source.
Click the 'action' link next to the zip file at the bottom of this page.
A big thankyou to StefanMainz for
introducing me to the wonders of the Velocity template engine with
his NewFromTemplatePlugin. Stefan, there are still vestiges of your
code in the Mirror plugin - duely credited, of course.
The Velocity templates supplied with the plugin will do the
following:
- Create a JUnit test skeleton file in the mirror directory for each source file added.
- For each source directory a "master" mirror file will be generated containing java code that will run the JUnit tests for that package and any subpackages.
- List all the Velocity variables that you have available. You can
delete this list by removing the line
#parse ("dump_variables.vm")
from the two templates (mirror_java.vm and mirror_master.vm).
If you already have an existing source tree, then you can
force the generation of the JUnit skeletons by right-clicking
the source file (or directory) in the Project View and
selecting the "Mirror" command.
- You must manually add the mirror output directory to your project source paths as there is currently no way (that I can see) to do this programmatically.
- If you rename a source file, then the mirror file will also be renamed, but the class names within the mirror file will remain unchanged. Judicious application of your keyboard typing skills to the offending mirror files should remedy the problem.
- As shipped, the JUnit skeletons cause IDEA to complain about unresolved package names - but they compile and run OK. I'm willing to put up with this because I like the way the mirror file names line up under the source files in the Project View (pretty lame, but it's the best excuse I've got). If you dont like the warnings, then you can change the templates to make the package names match the directory names.
- Due to catastrophic brain failure on the part of the author, the automatic generation of a test case for each method in a class will almost certainly not work! The new Psi API looks promising (and better anyway) as a solution.
- Unzip MirrorPlugin.zip to a directory of your choice.
- Open the MirrorPlugin.ipr project file in IDEA.
- Edit the build.xml file and adjust the property called "dir.idea" to match your IDEA installation directory:
- property name="dir.idea" value="d:/java/idea660"
- Run the default ant build target (which is "all"). This will:
- Compile the plugin into a jar.
- Copy the jar to $IDEA_HOME$/plugins.
- Copy sample Velocity macros to $IDEA_HOME$/plugins/templates.
- Stop and restart IDEA.
- The MirrorPlugin is disabled by default. You will have to get into File | Project Properties | MirrorPlugin and enable it.
- Open the Project Properties dialog and select MirrorPlugin. You can add your own Velocity variables here (which may define strings or classes). Each variable describes a named String or class that can be referenced in your Velocity templates.
- Dont forget to check the 'Enable Mirror Plugin' checkbox.
- Set the variable MIRROR_OUTPUT_PATH to where you want to store files generated by the mirror plugin. It may be a relative path. You will be prompted to create it and add it to your project source path.
- Add the MIRROR_OUTPUT_PATH to your project source path - the plugin will not work unless this is done.
- Now create a class, or right-click an existing class and choose the "Mirror" command.
- As supplied, a new directory under your project called "tst" should appear.
- To run the JUnit tests, right-click a mirror class and choose either the "Test" or "Run" command. It doesn't matter which, because "Run" invokes the main method which the templates, as supplied, generate, and "Test" uses introspection to run the tests.
It would be good if the location of the MIRROR_DIRECTORY, and not just the name could be set in the variables.-- FlorianHehlen - 17 Oct 2002
Done in 1.11
Note that MIRROR_DIRECTORY variable has now been replaced by two variables:
- MIRROR_OUTPUT_PATH - the output path (may be relative). This initially defaults to the 'tst' directory under your project.
- MIRROR_PACKAGE_PREFIX - the package prefix (e.g. tst) for generated source files.
-- AndrewArmstrong - 22 Oct 2002
|
|