Search in sources :

Example 1 with CarvingManager

use of org.evosuite.testcarver.extraction.CarvingManager in project evosuite by EvoSuite.

the class ObjectPoolManager method initialisePool.

public void initialisePool() {
    if (!Properties.OBJECT_POOLS.isEmpty()) {
        String[] poolFiles = Properties.OBJECT_POOLS.split(File.pathSeparator);
        if (poolFiles.length > 1)
            LoggingUtils.getEvoLogger().info("* Reading object pools:");
        else
            LoggingUtils.getEvoLogger().info("* Reading object pool:");
        for (String fileName : poolFiles) {
            logger.info("Adding object pool from file " + fileName);
            ObjectPool pool = ObjectPool.getPoolFromFile(fileName);
            if (pool == null) {
                logger.error("Failed to load object from " + fileName);
            } else {
                LoggingUtils.getEvoLogger().info(" - Object pool " + fileName + ": " + pool.getNumberOfSequences() + " sequences for " + pool.getNumberOfClasses() + " classes");
                addPool(pool);
            }
        }
        if (logger.isDebugEnabled()) {
            for (GenericClass key : pool.keySet()) {
                logger.debug("Have sequences for " + key + ": " + pool.get(key).size());
            }
        }
    }
    if (Properties.CARVE_OBJECT_POOL) {
        CarvingManager manager = CarvingManager.getInstance();
        for (Class<?> targetClass : manager.getClassesWithTests()) {
            List<TestCase> tests = manager.getTestsForClass(targetClass);
            logger.info("Carved tests for {}: {}", targetClass.getName(), tests.size());
            GenericClass cut = new GenericClass(targetClass);
            for (TestCase test : tests) {
                this.addSequence(cut, test);
            }
        }
        logger.info("Pool after carving: " + this.getNumberOfClasses() + "/" + this.getNumberOfSequences());
    }
}
Also used : CarvingManager(org.evosuite.testcarver.extraction.CarvingManager) GenericClass(org.evosuite.utils.generic.GenericClass) TestCase(org.evosuite.testcase.TestCase)

Example 2 with CarvingManager

use of org.evosuite.testcarver.extraction.CarvingManager in project evosuite by EvoSuite.

the class JUnitTestCarvedChromosomeFactory method readTestCases.

private void readTestCases() throws IllegalStateException {
    CarvingManager manager = CarvingManager.getInstance();
    final Class<?> targetClass = Properties.getTargetClassAndDontInitialise();
    List<TestCase> tests = manager.getTestsForClass(targetClass);
    junitTests.addAll(tests);
    if (junitTests.size() > 0) {
        totalNumberOfTestsCarved = junitTests.size();
        LoggingUtils.getEvoLogger().info("* Using {} carved tests from existing JUnit tests for seeding", junitTests.size());
        if (logger.isDebugEnabled()) {
            for (TestCase test : junitTests) {
                logger.debug("Carved Test: {}", test.toCode());
            }
        }
        TestSuiteChromosome suite = new TestSuiteChromosome();
        for (TestCase test : junitTests) {
            suite.addTest(test);
        }
        for (Properties.Criterion pc : Properties.CRITERION) {
            TestSuiteFitnessFunction f = FitnessFunctions.getFitnessFunction(pc);
            f.getFitness(suite);
        }
        carvedCoverage = suite.getCoverage();
    }
    ClientNodeLocal client = ClientServices.getInstance().getClientNode();
    client.trackOutputVariable(RuntimeVariable.CarvedTests, totalNumberOfTestsCarved);
    client.trackOutputVariable(RuntimeVariable.CarvedCoverage, carvedCoverage);
}
Also used : CarvingManager(org.evosuite.testcarver.extraction.CarvingManager) TestCase(org.evosuite.testcase.TestCase) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteFitnessFunction(org.evosuite.testsuite.TestSuiteFitnessFunction) ClientNodeLocal(org.evosuite.rmi.service.ClientNodeLocal) Properties(org.evosuite.Properties)

Aggregations

CarvingManager (org.evosuite.testcarver.extraction.CarvingManager)2 TestCase (org.evosuite.testcase.TestCase)2 Properties (org.evosuite.Properties)1 ClientNodeLocal (org.evosuite.rmi.service.ClientNodeLocal)1 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)1 TestSuiteFitnessFunction (org.evosuite.testsuite.TestSuiteFitnessFunction)1 GenericClass (org.evosuite.utils.generic.GenericClass)1