use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.
the class DeleteMutationSystemTest method getIntTest.
private TestCase getIntTest(int x, int y) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
test.addStatement(new IntPrimitiveStatement(test, x));
VariableReference wrongIntVar = test.addStatement(new IntPrimitiveStatement(test, y));
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { wrongIntVar }));
test.addStatement(ms);
return test;
}
use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.
the class InsertionMutationSystemTest method getIntTest.
private TestCase getIntTest(int x) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
VariableReference intVar = test.addStatement(new IntPrimitiveStatement(test, x));
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar }));
test.addStatement(ms);
return test;
}
use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.
the class InsertionMutationSystemTest method getTwoIntTest.
private TestCase getTwoIntTest(int x, int y) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
VariableReference intVar1 = test.addStatement(new IntPrimitiveStatement(test, x));
VariableReference intVar2 = test.addStatement(new IntPrimitiveStatement(test, y));
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class, int.class });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar1, intVar2 }));
test.addStatement(ms);
return test;
}
use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.
the class RegressionExceptionHelper method simpleExceptionName.
/**
* Get a simple (and unique looking) exception name (exType or exThrowingMethodCall:exType)
*/
public static String simpleExceptionName(RegressionTestChromosome test, Integer statementPos, Throwable ex) {
if (ex == null) {
return "";
}
String exception = ex.getClass().getSimpleName();
if (test.getTheTest().getTestCase().hasStatement(statementPos)) {
Statement exThrowingStatement = test.getTheTest().getTestCase().getStatement(statementPos);
if (exThrowingStatement instanceof MethodStatement) {
String exMethodcall = ((MethodStatement) exThrowingStatement).getMethod().getName();
exception = exMethodcall + ":" + exception;
}
}
return exception;
}
use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.
the class RegressionFitnessHelper method trackDiversity.
/**
* Diversity is based on the test case statements, and doesn't used with execution results
*/
static void trackDiversity(RegressionTestChromosome c, TestChromosome testChromosome) {
Map<String, Map<Integer, String>> testDiversityMap = new HashMap<>();
for (int i = 0; i < testChromosome.getTestCase().size(); i++) {
Statement x = testChromosome.getTestCase().getStatement(i);
if (x instanceof MethodStatement) {
MethodStatement methodCall = (MethodStatement) x;
VariableReference callee = methodCall.getCallee();
if (callee == null) {
continue;
}
int calleePosition = callee.getStPosition();
String calleeClass = callee.getClassName();
String methodCallName = methodCall.getMethod().getName();
Map<Integer, String> calleeMap = testDiversityMap.get(calleeClass);
if (calleeMap == null) {
calleeMap = new HashMap<Integer, String>();
}
String calledMethods = calleeMap.get(calleePosition);
if (calledMethods == null) {
calledMethods = "";
}
calledMethods += methodCallName;
calleeMap.put(calleePosition, calledMethods);
testDiversityMap.put(calleeClass, calleeMap);
}
}
c.diversityMap = testDiversityMap;
}
Aggregations