The first usable version of unittestsgen.jar is now available. You can downalod it under address: http://sourceforge.net/project/showfiles.php?group_id=31579
To learn more about this package please read the following text:
WHY Unit Tests Generator?
Lets assume you started developing your application some weeks ago or some months ago or even some years ago. I am sure that testing your code was one of major problems. You thought about automating such process. And than you heard about Unit Testing. So you would like to start use it. However how to introduce Unit Testing for large number of source files. There is too much of stupid code to write in all places again.
Here comes this package. His main goal is save you from wasting time for creating test classes for your all source files. It takes as an argument sources directory and than performs some actions which, result with test classes.
1. Searching in given directory for all source files. You can put as a parameter file mask which, can improve finding source files.
2. Parsing sources to structures which, can be processed later.
3. Generates test files for each given source.
At the moment I have ready to use source parser and code generator for Java language and JUnit package. There are many extensions I can see in this version but at the moment it is ready to use for simple test generating.
But it is very modular application and it very easy to use code parsers and generator for other languages and unit test systems. It is necessary only to create class which, performs proper actions and returns results. Using different parsers and generators is very easy only by passing class name as a parameter to command line arguments.
If you are interested in other languages support please let me know. If you are interested in creating pasrsers or generators for other languages and unit tests please let me know or join my project.
How can I use it?
Although by default it doesn't overwriting existing files remember that it is test version of application and always make backup of you project before use it.
unittestsgen.jar ommits all files which, name beggining with Test string or which, are extending TestCase class from JUnit package. All new classes are stored in files named TestSrcOriginalName.java.
If you run application with no arguments it display short description of all available parameters:
[user] $ java -jar unittestsgen.jar
The most common options are:
* -i directory -- input directory where are placed your source files.
* -cp classpath -- because if you run application java -jar jarfile.jar there is no way to pass CLASSPATH in standard way I provided option to add classpath through programm interface. Here you should put path to junit.jar your classes compiled version.
* -f -- force overwriting existing files. Hoever it is not save. You can lost your test files you created your own but if you use Unit Test Gen some times it is not very comfortable to remove all Test classes before generating them again. So you can use this option.
The most commonly you should use application in that way:
In unix like systems:
[user] $ java -jar jar/unittestsgen.jar -i src -cp "yourjarfile.jar:junit.jar"
In MS windows like systems:
D:\projects\yourproject> java -jar unittestsgen.jar -i src -cp "yourjarfile.jar;junit.jar"
I have some test classes and what?
If you have ready to use test classes (classes which, can be compiled with no problems) you can start unit testing. It can be done in many ways, however preferred are:
* Run tests for one class only, for example for this class you can test with command:
java -cp "jar/thisjarfile.jar;lib/junit.jar" full.class.Name
* Run tests for all classes in one command call. Code generator creates also TestAll.class which, runs all available tests:
java -cp "jar/thisjarfile.jar;lib/junit.jar" TestAll
* But the most preferred way is to run all tests from Ant just after compilation process finished.
To do it. You need:
1. Ant package from Ant
2. JUnit package from JUnit
3. Put some code in your build.xml file to tell Ant how to test your package. Sample code for Ant's build.xml you can find in created file: sample-junit-build.xml. And remember to have junit.jar in CLASSPATH before you run Ant.
Need more info?
If you have any problems with this application or you found any bugs or you have any ideas about extending this package, want to join to project or you simply need to contact me please send e-mail to addres: Artur Hefczyc email@example.com
This part of Web Test Tools project.