|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--org.apache.tools.ant.ProjectComponent
|
+--org.apache.tools.ant.Task
|
+--testsgen.taskant.UnitTestsGen
UnitTestsGen.java extends org.apache.tools.ant.Task
extension. It implements task which allows use Unit Tests Generator
from ANT and controll test classes genrating from build.xml
file.
It is very simple at the moment and support only subset of features offered by
'ANT'.
To use it in your developing process you must define new task in your
build.xml. To do this put in the beggining of your build file such lines:
<taskdef name="unitgen"
classpath="some_dir/unittestsgen.jar"
classname="testsgen.taskant.UnitTestsGen"/>
Where, of course, 'some_dir' is directory where 'unittestsgen.jar'
file exists.build.xml
sample.
<project name="UnitTestsGen" default="dist" basedir=".">
<taskdef name="unitgen" classname="testsgen.taskant.UnitTestsGen"/>
<property name="src" value="src"/>
<property name="test-src" value="test-src"/>
<property name="build" value="build"/>
<target name="compile" description="Compile sources in ${tmpsrc} directory">
<mkdir dir="${build}"/>
<javac srcdir="${src};${test-src}" destdir="${build}"
debug="on" deprecation="off">
<classpath>
<pathelement location="${libs}/junit.jar"/>
</classpath>
</javac>
</target>
<target name="jar" depends="compile">
<jar jarfile="jar/${jarfile}.jar" manifest="MANIFEST.MF" basedir="${build}">
<exclude name="** /*TestCase*.*"/>
<exclude name="TestAll.*"/>
</jar>
<unitgen update="true" classpath="${build};${libs}/junit.jar"
imput="${src}" output="${test-src}"/>
</target>
</project>
After excecuting command 'ant jar' you should see similar output:
compile:
[javac] Compiling 36 source files to /home/kobit/projects/unittestsgen/build
jar:
[jar] Building jar: /home/kobit/projects/unittestsgen/jar/unittestsgen.jar
[unitgen] Finished work: files 21, sources 14, new classes 3, new methods 7
BUILD SUCCESSFUL
Every time you will be building jar file all your source classes will be checked
against changes made and test classes will be updated if necessary.
Below you can read detailed list of all supported attributes. All given attributes
are translated to command line parameters form for GenerateTests
class. So you can find similar list but with a little different names in this class
documentation.
In description titles you have sample use code. Given values are default in most cases.
If there are given multiple options first one is default. There are some differencies
in defaults values between ANT task mode and command line mode.
build.xml file but it is possible. Additionaly you must
note that content of this file should contain names of the command line form. See
GenerateTests.java documentation for complete list of command line
parameters or run this tool from command line as following:
java -jar unittestsgen.jar --helpAs you can see there are a lot of possible parameters for running this application. Although almost all defaults are suitable for most cases if you use different options it is very difficult to run tool every time with long list of command line parameters.
key = valueWhere key is name of command line parameter you want to set. You can also use there comments: Lines which starts with '#' character. and blank lines.
classpath element in common ANT use.
input and output directories. But stored will always
in output directory tree.
output directory even if they found in
input directory.
output directory even if they found in input directory.
Created: Thu Jan 31 08:37:42 2002
| Field Summary | |
protected org.apache.tools.ant.types.CommandlineJava |
commandline
|
static java.lang.String |
created
|
static java.lang.String |
dedicated
|
protected static java.lang.String |
PAR_CLASSPATH
|
protected static java.lang.String |
PAR_CODEGEN
|
protected static java.lang.String |
PAR_CONFIG
|
protected static java.lang.String |
PAR_CONTENT
|
protected static java.lang.String |
PAR_DEBUG
|
protected static java.lang.String |
PAR_DIRWALKER
|
protected static java.lang.String |
PAR_FORCE
|
protected static java.lang.String |
PAR_HELP
|
protected static java.lang.String |
PAR_IMPLEMENTATIONS
|
protected static java.lang.String |
PAR_INPUT
|
protected static java.lang.String |
PAR_LOGIMPL
|
protected static java.lang.String |
PAR_MASK
|
protected static java.lang.String |
PAR_OUTPUT
|
protected static java.lang.String |
PAR_PARSER
|
protected static java.lang.String |
PAR_PATTERN
|
protected static java.lang.String |
PAR_PROPERTYIMPL
|
protected static java.lang.String |
PAR_QUIET
|
protected static java.lang.String |
PAR_RECURSIVE
|
protected static java.lang.String |
PAR_TARGET
|
protected static java.lang.String |
PAR_TEST
|
protected static java.lang.String |
PAR_UPDATE
|
protected static java.lang.String |
PAR_VERSION
|
protected java.util.Properties |
prop
|
static java.lang.String |
version
|
| Fields inherited from class org.apache.tools.ant.Task |
description, location, target, taskName, taskType, wrapper |
| Fields inherited from class org.apache.tools.ant.ProjectComponent |
project |
| Constructor Summary | |
UnitTestsGen()
Creates a new UnitTestsGen instance. |
|
| Method Summary | |
org.apache.tools.ant.types.Path |
createClasspath()
Method createClasspath sets internal parameter
to given Classpath attribute value. |
void |
execute()
execute method performs ANT task work here. |
void |
init()
init method sets start parameters for unit tests generator such as
'imput' and 'output' dirs to default values. |
void |
setClasspath(java.lang.String clp)
Method setClasspath sets internal parameter
to given Classpath attribute value. |
void |
setCodegen(java.lang.String codeg)
Method setCodegen sets internal parameter
to given Codegen attribute value. |
void |
setConfig(java.lang.String cfg)
Method setConfig sets internal parameter
to given Config attribute value. |
void |
setContent(java.lang.String cont)
Method setContent sets internal parameter
to given Content attribute value. |
void |
setDebug(java.lang.String debug)
Method setDebug sets internal parameter
to given Debug attribute value. |
void |
setDirwalker(java.lang.String dirw)
Method setDirwalker sets internal parameter
to given Dirwalker attribute value. |
void |
setHelp(java.lang.String help)
Method setHelp sets internal parameter
to given Help attribute value. |
void |
setImplementations(java.lang.String imp)
Method setImplementations sets internal parameter
to given Implementations attribute value. |
void |
setInput(java.lang.String indir)
Method setInput sets internal parameter
to given Input attribute value. |
void |
setLogimpl(java.lang.String log)
Method setLogimpl sets internal parameter
to given Logimpl attribute value. |
void |
setMask(java.lang.String mask)
Method setMask sets internal parameter
to given Mask attribute value. |
void |
setOutput(java.lang.String outdir)
Method setOutput sets internal parameter
to given Output attribute value. |
void |
setOverwrite(java.lang.String over)
Method setOverwrite sets internal parameter
to given Overwrite attribute value. |
void |
setParser(java.lang.String par)
Method setParser sets internal parameter
to given Parser attribute value. |
void |
setPattern(java.lang.String pat)
Method setPattern sets internal parameter
to given Pattern attribute value. |
void |
setPropertyimpl(java.lang.String pr)
Method setPropertyimpl sets internal parameter
to given Propertyimpl attribute value. |
void |
setQuiet(java.lang.String quiet)
Method setQuiet sets internal parameter
to given Quiet attribute value. |
void |
setRecursive(java.lang.String rec)
Method setRecursive sets internal parameter
to given Recursive attribute value. |
void |
setTarget(java.lang.String tar)
Method setTarget sets internal parameter
to given Target attribute value. |
void |
setTest(java.lang.String test)
Method setTest sets internal parameter
to given Test attribute value. |
void |
setUpdate(java.lang.String update)
Method setUpdate sets internal parameter
to given Update attribute value. |
void |
setVersion(java.lang.String ver)
Method setVersion sets internal parameter
to given Version attribute value. |
| Methods inherited from class org.apache.tools.ant.Task |
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName |
| Methods inherited from class org.apache.tools.ant.ProjectComponent |
getProject, setProject |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final java.lang.String PAR_CLASSPATH
protected static final java.lang.String PAR_CONFIG
protected static final java.lang.String PAR_FORCE
protected static final java.lang.String PAR_INPUT
protected static final java.lang.String PAR_PATTERN
protected static final java.lang.String PAR_OUTPUT
protected static final java.lang.String PAR_CONTENT
protected static final java.lang.String PAR_MASK
protected static final java.lang.String PAR_RECURSIVE
protected static final java.lang.String PAR_TEST
protected static final java.lang.String PAR_QUIET
protected static final java.lang.String PAR_DEBUG
protected static final java.lang.String PAR_HELP
protected static final java.lang.String PAR_VERSION
protected static final java.lang.String PAR_IMPLEMENTATIONS
protected static final java.lang.String PAR_TARGET
protected static final java.lang.String PAR_LOGIMPL
protected static final java.lang.String PAR_PROPERTYIMPL
protected static final java.lang.String PAR_DIRWALKER
protected static final java.lang.String PAR_PARSER
protected static final java.lang.String PAR_CODEGEN
protected static final java.lang.String PAR_UPDATE
public static final java.lang.String version
public static final java.lang.String created
public static final java.lang.String dedicated
protected org.apache.tools.ant.types.CommandlineJava commandline
protected java.util.Properties prop
| Constructor Detail |
public UnitTestsGen()
UnitTestsGen instance.| Method Detail |
public void init()
init method sets start parameters for unit tests generator such as
'imput' and 'output' dirs to default values.init in class org.apache.tools.ant.Task
public void execute()
throws org.apache.tools.ant.BuildException
execute method performs ANT task work here. in particular
it calls GenerateTests class for performing standard processing
actions. As parameter GenerateTests gets Properties
structure containing all options set by user or as default values.execute in class org.apache.tools.ant.Taskorg.apache.tools.ant.BuildException - if an error occurspublic void setConfig(java.lang.String cfg)
setConfig sets internal parameter
to given Config attribute value.
config="gentest.cfg"
This attribute is useful for command line running this tool. It is not very suitable
for using it in build.xml file but it is possible. Additionaly you must
note that content of this file should contain names of the command line form. See
GenerateTests.java documentation for complete list of command line
parameters or run this tool from command line as following:
java -jar unittestsgen.jar --helpAs you can see there are a lot of possible parameters for running this application. Although almost all defaults are suitable for most cases if you use different options it is very difficult to run tool every time with long list of command line parameters.
key = valueWhere key is name of command line parameter you want to set. You can also use there comments: Lines which starts with '#' character. and blank lines.
cfg - a String valuepublic void setClasspath(java.lang.String clp)
setClasspath sets internal parameter
to given Classpath attribute value.
classpath="your_class_files;libs.jar;junit.jar"
Where your class file should be jar file containing your all compiled files including
test classes or directory where lies all your compiled files.classpath element in common ANT use.clp - a String valuepublic org.apache.tools.ant.types.Path createClasspath()
createClasspath sets internal parameter
to given Classpath attribute value.
classpath="your_class_files;libs.jar;junit.jar"
Where your class file should be jar file containing your all compiled files including
test classes or directory where lies all your compiled files.classpath element in common ANT use.Path valuepublic void setInput(java.lang.String indir)
setInput sets internal parameter
to given Input attribute value.
input="src"
Process files in given directory. But note that test classes will be searched in
both input and output directories. But stored will always
in output directory tree.indir - a String valuepublic void setPattern(java.lang.String pat)
setPattern sets internal parameter
to given Pattern attribute value.
pattern="*TestCase.java"
Pattern for creating names of test classes. The most commonly used standards are to put
'Test' string at the beginning of source class name or at the end of class name.pat - a String valuepublic void setOutput(java.lang.String outdir)
setOutput sets internal parameter
to given Output attribute value.
output="test-src"
Store test files in this given directory.outdir - a String valuepublic void setContent(java.lang.String cont)
setContent sets internal parameter
to given Content attribute value.
content="both|empty|code|comments"
Set here what you want to have in new generated test methods.
cont - a String valuepublic void setOverwrite(java.lang.String over)
setOverwrite sets internal parameter
to given Overwrite attribute value.
overwrite="false|true"
Force overwriting existing files. And additionaly please note that new test classes will
be always created in output directory even if they found in
input directory.over - a String valuepublic void setMask(java.lang.String mask)
setMask sets internal parameter
to given Mask attribute value.
mask="*.java" Process source files with given file mask. At the moment there is
very limited support for this feature.mask - a String valuepublic void setRecursive(java.lang.String rec)
setRecursive sets internal parameter
to given Recursive attribute value.
recursive="true|false" Recursive directories processing.rec - a String valuepublic void setTest(java.lang.String test)
setTest sets internal parameter
to given Test attribute value.
test="false|true" Test only mode don't make any changes on disk.test - a String valuepublic void setQuiet(java.lang.String quiet)
setQuiet sets internal parameter
to given Quiet attribute value.
quiet="true|false" Don't display any messages on screen.quiet - a String valuepublic void setDebug(java.lang.String debug)
setDebug sets internal parameter
to given Debug attribute value.
debug="false|true" Display additional debug messages.debug - a String valuepublic void setHelp(java.lang.String help)
setHelp sets internal parameter
to given Help attribute value.
help="false|true" Display help message and exit program. I don't expect it as
useful feature for ANT task mode but I left it here for full compatibility
with command line mode.help - a String valuepublic void setVersion(java.lang.String ver)
setVersion sets internal parameter
to given Version attribute value.
version="false|true" Display version info and exit program. I don't expect it as
useful feature for ANT task mode but I left it here for full compatibility
with command line mode.ver - a String valuepublic void setImplementations(java.lang.String imp)
setImplementations sets internal parameter
to given Implementations attribute value.
implementations="testsgen.wttools"
Package where are all modules implementations necessary for file processing.imp - a String valuepublic void setTarget(java.lang.String tar)
setTarget sets internal parameter
to given Target attribute value.
target="testsgen.wttools.CodeGenImpl"
Name of class which generate code for unit test. It must be 'CodeGenIfc' implementation.tar - a String valuepublic void setLogimpl(java.lang.String log)
setLogimpl sets internal parameter
to given Logimpl attribute value.
logimpl="testsgen.wttools.LogImpl"
Name of class which implements logging facility. It must be 'LogIfc' implementation.log - a String valuepublic void setPropertyimpl(java.lang.String pr)
setPropertyimpl sets internal parameter
to given Propertyimpl attribute value.
propertyimpl="testsgen.wttools.PropertyImpl"
Name of class which implements property access facility. It must be 'PropertyIfc'
implementation.pr - a String valuepublic void setDirwalker(java.lang.String dirw)
setDirwalker sets internal parameter
to given Dirwalker attribute value.
dirwalker="testsgen.wttools.DirWalkerImpl"
Name of class which provides file names list to process. It must be 'DirWalkerIfc'
implementation.dirw - a String valuepublic void setParser(java.lang.String par)
setParser sets internal parameter
to given Parser attribute value.
parser="testsgen.wttools.SrcParserImpl"
Name of class which parses source code. In other words it should provide list of
preparsed structures which identifies source files. It must be 'SrcParserIfc'
implementation.par - a String valuepublic void setCodegen(java.lang.String codeg)
setCodegen sets internal parameter
to given Codegen attribute value.codeg - a String valuepublic void setUpdate(java.lang.String update)
setUpdate sets internal parameter
to given Update attribute value.
codegen="testsgen.wttools.CodeGenImpl"
Name of class which generate code for unit test. It is synonym for --target-unit-test class.update - a String value
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||