use of org.evosuite.testcase.statements.Statement in project evosuite by EvoSuite.
the class Archive method hasFunctionalMocksForGenerableTypes.
private boolean hasFunctionalMocksForGenerableTypes(TestCase testCase) {
for (Statement statement : testCase) {
if (statement instanceof FunctionalMockStatement) {
FunctionalMockStatement fm = (FunctionalMockStatement) statement;
Class<?> target = fm.getTargetClass();
GenericClass gc = new GenericClass(target);
if (TestCluster.getInstance().hasGenerator(gc)) {
return true;
}
}
}
return false;
}
use of org.evosuite.testcase.statements.Statement in project evosuite by EvoSuite.
the class TestSuiteSerialization method loadTests.
public static List<TestChromosome> loadTests(File target) throws IllegalArgumentException {
Inputs.checkNull(target);
List<TestChromosome> list = new ArrayList<>();
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(target))) {
try {
Object obj = in.readObject();
while (obj != null) {
if (obj instanceof TestChromosome) {
// this check might fail if old version is used, and EvoSuite got updated
TestChromosome tc = (TestChromosome) obj;
for (Statement st : tc.getTestCase()) {
st.changeClassLoader(TestGenerationContext.getInstance().getClassLoaderForSUT());
}
list.add(tc);
}
obj = in.readObject();
}
} catch (EOFException e) {
// fine
} catch (Exception e) {
logger.warn("Problems when reading a serialized test from " + target.getAbsolutePath() + " : " + e.getMessage());
}
in.close();
} catch (FileNotFoundException e) {
logger.warn("Cannot load tests because file does not exist: " + target.getAbsolutePath());
} catch (IOException e) {
logger.error("Failed to open/handle " + target.getAbsolutePath() + " for reading: " + e.getMessage());
}
return list;
}
use of org.evosuite.testcase.statements.Statement in project evosuite by EvoSuite.
the class ParameterLocalSearch method doSearch.
/* (non-Javadoc)
* @see org.evosuite.testcase.LocalSearch#doSearch(org.evosuite.testcase.TestChromosome, int, org.evosuite.ga.LocalSearchObjective)
*/
/**
* {@inheritDoc}
*/
@Override
public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) {
Statement stmt = test.getTestCase().getStatement(statement);
backup(test, stmt);
if (stmt instanceof MethodStatement) {
return doSearch(test, (MethodStatement) stmt, objective);
} else if (stmt instanceof ConstructorStatement) {
return doSearch(test, (ConstructorStatement) stmt, objective);
} else if (stmt instanceof FieldStatement) {
return doSearch(test, (FieldStatement) stmt, objective);
} else {
return false;
}
}
use of org.evosuite.testcase.statements.Statement 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.Statement 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