use of org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator in project evosuite by EvoSuite.
the class CarvingRunListener method processLog.
/**
* Creates TestCase out of the captured log
*
* @param description
* @param log
* log captured from test execution
*/
private void processLog(Description description, final CaptureLog log) {
final CaptureLogAnalyzer analyzer = new CaptureLogAnalyzer();
final EvoTestCaseCodeGenerator codeGen = new EvoTestCaseCodeGenerator();
logger.debug("Current log: " + log);
List<Class<?>> observedClasses = getObservedClasses(log);
for (Class<?> targetClass : observedClasses) {
logger.debug("Current observed class: {}", targetClass.getName());
Class<?>[] targetClasses = new Class<?>[1];
targetClasses[0] = targetClass;
if (!carvedTests.containsKey(targetClass))
carvedTests.put(targetClass, new ArrayList<TestCase>());
analyzer.analyze(log, codeGen, targetClasses);
CarvedTestCase test = (CarvedTestCase) codeGen.getCode();
if (test == null) {
logger.info("Failed to carve test for " + Arrays.asList(targetClasses));
codeGen.clear();
continue;
}
test.setName(description.getMethodName());
logger.info("Carved test of length " + test.size());
try {
test.changeClassLoader(TestGenerationContext.getInstance().getClassLoaderForSUT());
GenericTypeInference inference = new GenericTypeInference();
// test.accept(inference);
inference.inferTypes(test);
carvedTests.get(targetClass).add(test);
} catch (Throwable t) {
logger.info("Exception during carving: " + t);
for (StackTraceElement elem : t.getStackTrace()) {
logger.info(elem.toString());
}
logger.info(test.toCode());
}
codeGen.clear();
}
}
use of org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator in project evosuite by EvoSuite.
the class CarvingTestRunner method processLog.
/**
* Creates TestCase out of the captured log
*
* @param log log captured from test execution
*/
private void processLog(final CaptureLog log) {
final CaptureLogAnalyzer analyzer = new CaptureLogAnalyzer();
final EvoTestCaseCodeGenerator codeGen = new EvoTestCaseCodeGenerator();
analyzer.analyze(log, codeGen, this.targetClasses);
this.carvedTest = codeGen.getCode();
codeGen.clear();
}
Aggregations