|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjartege.ClassTester
Class that allows one to generate random tests for a specified set of
classes.
A typical use of this class is as follows:
A weight is positive or null double value associated with
each class and each visible operation of
class (constructors, methods and operations get and set for each visible
field).
By default, all weights are equal to 1.
The program generates a method call according to the specified weights.
Weights can be changed with change weight methods.
The following statement change the weight of
public static void main(String[] args) {
ClassTester t = new ClassTester(args) ;
}
t.addClass("packageName.ClassA") ;
t.addClass("packageName.ClassB") ;
t.changeClassWeight("packageName.ClassA", 9) ;
t.changeCreationProbability("packageName.ClassA",
new ThresholdProbability(1)) ;
t.addImportedPackage("packageName") ;
t.generate("TestForAandB", 10, 50) ;
packageName.ClassA
to 9.
A creation probability function is associated with each class under
test. This function commands the creation of new objects of the
class, according to the number of already created objects.
t.changeClassWeight("packageName.ClassA", 9) ;
The statement
changes the creation threshold function of class
t.changeCreationProbability("packageName.ClassA",
new ThresholdProbability(1)) ;
ClassA
to the specified probability function,
which allows the creation of at most one object of ClassA
.
The statement
add the package
t.addImportedPackage("packageName") ;
packageName
to the set of imported packages.
For each imported package, the generator generates a line
in the generated test file.
import packageName.* ;
The statement
generates a test file
t.generate("TestForAandB", 10, 50) ;
"TestForAandB.java"
.
This file consists of a class called "TestForAandB"
which contains 10 test methods. For each test method, the tool
tries to generate 50 method calls in classes ClassA
and ClassB
. For each generated call, ClassA
will be choosen with a probablity of 0.9 while ClassB
will be chosen with a probability of 0.1.
Field Summary | |
static CreationProbability |
creationProbabilityFew
Probability function that allows the creation of few objects. |
static CreationProbability |
creationProbabilityMany
Probability function that allows the creation of many objects. |
static CreationProbability |
creationProbabilityNormal
Normal creation probability function. |
Constructor Summary | |
ClassTester()
Constructs a new class tester. |
|
ClassTester(java.lang.String[] args)
Constructs a new class tester. |
Method Summary | |
void |
addClass(java.lang.String className)
Adds the class with the specified name to the set of classes under test. |
void |
addContext(java.lang.String className)
Add the specified class to the context. |
void |
addImportedClass(java.lang.String className)
Adds the specified class to the set of imported classes. |
void |
addImportedPackage(java.lang.String packageName)
Adds the specified package to the set of imported packages. |
void |
changeAllConstructorsWeight(java.lang.String className,
double weight)
In class with the specified name, changes all constructors weight to the specified weight. |
void |
changeAllMethodsWeight(java.lang.String className,
double weight)
In class with the specified name, changes all methods weight to the specified weight. |
void |
changeClassWeight(java.lang.String className,
double weight)
Changes the weight of class with the specified name to the specified weight. |
void |
changeConstructorWeight(java.lang.String constructorName,
java.lang.String[] theSignature,
double weight)
In class with the specified name className , changes the
weight of the constructor with the specified name
constructorName
and specified signature to the specified weight. |
void |
changeCreationProbability(java.lang.String className,
CreationProbability function)
Changes the creation probability function of the specified class to the specified function. |
void |
changeGetWeight(java.lang.String className,
java.lang.String fieldName,
double weight)
Changes the weight of the get operation associated with the specified field in the specified class to the specified weight. |
void |
changeMethodWeight(java.lang.String className,
java.lang.String methodName,
double weight)
In class with the specified name className , changes the
weight of all methods with the specified name
methodName to the specified weight. |
void |
changeMethodWeight(java.lang.String className,
java.lang.String methodName,
java.lang.String[] theSignature,
double weight)
In class with the specified name className , changes the
weight of the method with the specified name methodName
and specified signature to the specified weight. |
void |
changeObjectGenerator(java.lang.String className,
jartege.ObjectGenerator objectGen)
Change the object generator associated with the class with the specified name className to the specified
object generator. |
void |
changeSetWeight(java.lang.String className,
java.lang.String fieldName,
double weight)
Changes the weight of the set operation associated with the specified field in the specified class to the specified weight. |
void |
generate(java.lang.String className,
int numberOfMethodCalls)
Generates a test class with the specified name className .
|
void |
generate(java.lang.String className,
int numberOfTests,
int numberOfMethodCalls)
Generates a test class with the specified name className . |
java.util.Set |
getClasses()
Returns the set of classes under test of this class tester. |
CreationProbability |
getCreationProbability(java.lang.String className)
Returns the creation probability associated with the specified class. |
java.lang.String |
getDir()
Returns the directory in which the test file is generated. |
boolean |
getForJUnit()
Returns the ForJUnit flag value. |
double |
getGetWeight(java.lang.String className,
java.lang.String fieldName)
Gets the weight of the get operation associated with the specified field in the specified class. |
java.util.Set |
getImportedClasses()
Returns the set of imported classes. |
java.util.Set |
getImportedPackages()
Returns the set of imported packages. |
java.lang.String |
getPackage()
Returns the package name of the generated test file. |
double |
getSetWeight(java.lang.String className,
java.lang.String fieldName)
Gets the weight of the get operation associated with the specified field in the specified class. |
java.lang.Class |
getToExtendClass()
Returns the class that the generated test class extends. |
void |
removeAllClasses()
Removes all classes under test in this class tester. |
void |
removeClass(java.lang.String className)
Remove the class with the specified name to the set of classes under test. |
void |
resetContext()
Reinitialises the context. |
void |
setAllMethodsStoreResult(java.lang.String className,
boolean storeResult)
Sets the storeResult flag of all methods in the specified class to the specified boolean value. |
void |
setDir(java.lang.String dirName)
Sets the directory in which the test file is generated to the specified directory name. |
void |
setForJUnit(boolean b)
Sets the ForJUnit flag to the specified boolean value. |
void |
setMethodStoreResult(java.lang.String className,
java.lang.String methodName,
boolean storeResult)
Sets the storeResult flag of method with the specified name in the specified class to the specified boolean value. |
void |
setMethodStoreResult(java.lang.String className,
java.lang.String methodName,
java.lang.String[] signature,
boolean storeResult)
Indicates that results of method calls with the specified name with the specified signature in the specified class should not be stored in variables. |
void |
setPackage(java.lang.String packageName)
Sets the package name of the generated test file to the specified package name. |
void |
setToExtendClass(java.lang.String toExtendClassName)
Defines the class that the generator extends. |
void |
unsetToExtendClass()
Unsets the class that the generated test class extends. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static CreationProbability creationProbabilityNormal
theFunction(n) = 1.0 / (1.0 + n) ;
public static CreationProbability creationProbabilityFew
theFunction(n) = 1.0 / ((1.0 + n) * (1.0 + n)) ;
public static CreationProbability creationProbabilityMany
theFunction(n) = 1.0 / Math.sqrt(1.0 + n) ;
Constructor Detail |
public ClassTester(java.lang.String[] args)
args
- the arguments of the command line.public ClassTester()
Method Detail |
public void addContext(java.lang.String className)
public java.lang.String getPackage()
public void resetContext()
public void setPackage(java.lang.String packageName)
packageName
- the name of the package in which the
test file is generated.public void setDir(java.lang.String dirName)
dirName
- the name of the directory in which the test file
is generated.public java.lang.String getDir()
setDir(java.lang.String)
public void setForJUnit(boolean b)
public boolean getForJUnit()
public void addImportedPackage(java.lang.String packageName)
import packageName.* ;
in the generated test file.
packageName
- the name of the package that has to be imported.addImportedClass(java.lang.String)
public java.util.Set getImportedPackages()
public void addImportedClass(java.lang.String className)
import className ;
in the generated test file.
className
- the name of the class that has to be imported.addImportedPackage(java.lang.String)
public java.util.Set getImportedClasses()
public void setToExtendClass(java.lang.String toExtendClassName)
unsetToExtendClass()
method.
toExtendClassName
- the name of the class that will be extended
by the generator.unsetToExtendClass()
public java.lang.Class getToExtendClass()
public void unsetToExtendClass()
setToExtendClass(java.lang.String)
public void addClass(java.lang.String className)
className
- the name of the class which is added in the set
of classes under test.public void removeClass(java.lang.String className)
className
- the name of the class which is removed of the set
of classes under test.public void removeAllClasses()
public java.util.Set getClasses()
public void changeClassWeight(java.lang.String className, double weight)
public void changeAllMethodsWeight(java.lang.String className, double weight)
public void changeAllConstructorsWeight(java.lang.String className, double weight)
public void changeMethodWeight(java.lang.String className, java.lang.String methodName, double weight)
className
, changes the
weight of all methods with the specified name
methodName
to the specified weight.
public void changeMethodWeight(java.lang.String className, java.lang.String methodName, java.lang.String[] theSignature, double weight)
className
, changes the
weight of the method with the specified name methodName
and specified signature to the specified weight.
public void changeConstructorWeight(java.lang.String constructorName, java.lang.String[] theSignature, double weight)
className
, changes the
weight of the constructor with the specified name
constructorName
and specified signature to the specified weight.
public void changeGetWeight(java.lang.String className, java.lang.String fieldName, double weight)
public void changeSetWeight(java.lang.String className, java.lang.String fieldName, double weight)
public double getGetWeight(java.lang.String className, java.lang.String fieldName)
className
- name of the class.fieldName
- field name in the specified class.public double getSetWeight(java.lang.String className, java.lang.String fieldName)
className
- name of the class.fieldName
- field name in the specified class.public void changeCreationProbability(java.lang.String className, CreationProbability function)
public CreationProbability getCreationProbability(java.lang.String className)
public void setAllMethodsStoreResult(java.lang.String className, boolean storeResult)
public void setMethodStoreResult(java.lang.String className, java.lang.String methodName, boolean storeResult)
public void setMethodStoreResult(java.lang.String className, java.lang.String methodName, java.lang.String[] signature, boolean storeResult)
public void changeObjectGenerator(java.lang.String className, jartege.ObjectGenerator objectGen)
className
to the specified
object generator.
className
- the name of the class.objectGen
- the object generator.public void generate(java.lang.String className, int numberOfTests, int numberOfMethodCalls)
className
.
className
- the name of the generated test class.numberOfTests
- the number of test methods generated in the
class.numberOfMethodCalls
- the number of method calls the generator
tries to generate for each test method.public void generate(java.lang.String className, int numberOfMethodCalls)
className
.
This is equivalent to generate(className, 1, numberOfMethodCalls)
className
- the name of the generated test class.numberOfMethodCalls
- the number of method calls the generator
tries to generate.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |