Search in sources :

Example 1 with CaptureLogAnalyzer

use of org.evosuite.testcarver.codegen.CaptureLogAnalyzer 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();
    }
}
Also used : CaptureLogAnalyzer(org.evosuite.testcarver.codegen.CaptureLogAnalyzer) CarvedTestCase(org.evosuite.testcarver.testcase.CarvedTestCase) ArrayList(java.util.ArrayList) GenericTypeInference(org.evosuite.utils.generic.GenericTypeInference) EvoTestCaseCodeGenerator(org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator)

Example 2 with CaptureLogAnalyzer

use of org.evosuite.testcarver.codegen.CaptureLogAnalyzer 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();
}
Also used : CaptureLogAnalyzer(org.evosuite.testcarver.codegen.CaptureLogAnalyzer) EvoTestCaseCodeGenerator(org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator)

Aggregations

CaptureLogAnalyzer (org.evosuite.testcarver.codegen.CaptureLogAnalyzer)2 EvoTestCaseCodeGenerator (org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator)2 ArrayList (java.util.ArrayList)1 CarvedTestCase (org.evosuite.testcarver.testcase.CarvedTestCase)1 GenericTypeInference (org.evosuite.utils.generic.GenericTypeInference)1