Search in sources :

Example 1 with JUnitTestCarvedChromosomeFactory

use of org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory in project evosuite by EvoSuite.

the class PropertiesNoveltySearchFactory method getChromosomeFactory.

private ChromosomeFactory<TestChromosome> getChromosomeFactory() {
    switch(Properties.TEST_FACTORY) {
        case ALLMETHODS:
            logger.info("Using all methods chromosome factory");
            return new AllMethodsTestChromosomeFactory();
        case RANDOM:
            logger.info("Using random chromosome factory");
            return new RandomLengthTestFactory();
        case ARCHIVE:
            logger.info("Using archive chromosome factory");
            return new ArchiveTestChromosomeFactory();
        case JUNIT:
            logger.info("Using seeding chromosome factory");
            JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory(new RandomLengthTestFactory());
            return factory;
        case SERIALIZATION:
            logger.info("Using serialization seeding chromosome factory");
            return new RandomLengthTestFactory();
        default:
            throw new RuntimeException("Unsupported test factory: " + Properties.TEST_FACTORY);
    }
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) RandomLengthTestFactory(org.evosuite.testcase.factories.RandomLengthTestFactory) AllMethodsTestChromosomeFactory(org.evosuite.testcase.factories.AllMethodsTestChromosomeFactory) ArchiveTestChromosomeFactory(org.evosuite.ga.archive.ArchiveTestChromosomeFactory)

Example 2 with JUnitTestCarvedChromosomeFactory

use of org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory in project evosuite by EvoSuite.

the class PropertiesSuiteGAFactory method getChromosomeFactory.

protected ChromosomeFactory<TestSuiteChromosome> getChromosomeFactory() {
    switch(Properties.STRATEGY) {
        case EVOSUITE:
            switch(Properties.TEST_FACTORY) {
                case ALLMETHODS:
                    logger.info("Using all methods chromosome factory");
                    return new TestSuiteChromosomeFactory(new AllMethodsTestChromosomeFactory());
                case RANDOM:
                    logger.info("Using random chromosome factory");
                    return new TestSuiteChromosomeFactory(new RandomLengthTestFactory());
                case ARCHIVE:
                    logger.info("Using archive chromosome factory");
                    return new TestSuiteChromosomeFactory(new ArchiveTestChromosomeFactory());
                case JUNIT:
                    logger.info("Using seeding chromosome factory");
                    JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory(new RandomLengthTestFactory());
                    return new TestSuiteChromosomeFactory(factory);
                case SERIALIZATION:
                    logger.info("Using serialization seeding chromosome factory");
                    return new SerializationSuiteChromosomeFactory(new RandomLengthTestFactory());
                default:
                    throw new RuntimeException("Unsupported test factory: " + Properties.TEST_FACTORY);
            }
        case REGRESSION:
            return new RegressionTestSuiteChromosomeFactory();
        case MOSUITE:
            return new TestSuiteChromosomeFactory(new RandomLengthTestFactory());
        default:
            throw new RuntimeException("Unsupported test factory: " + Properties.TEST_FACTORY);
    }
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) TestSuiteChromosomeFactory(org.evosuite.testsuite.factories.TestSuiteChromosomeFactory) RegressionTestSuiteChromosomeFactory(org.evosuite.regression.RegressionTestSuiteChromosomeFactory) RandomLengthTestFactory(org.evosuite.testcase.factories.RandomLengthTestFactory) AllMethodsTestChromosomeFactory(org.evosuite.testcase.factories.AllMethodsTestChromosomeFactory) SerializationSuiteChromosomeFactory(org.evosuite.testsuite.factories.SerializationSuiteChromosomeFactory) RegressionTestSuiteChromosomeFactory(org.evosuite.regression.RegressionTestSuiteChromosomeFactory) ArchiveTestChromosomeFactory(org.evosuite.ga.archive.ArchiveTestChromosomeFactory)

Example 3 with JUnitTestCarvedChromosomeFactory

use of org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory in project evosuite by EvoSuite.

the class JUnitAnalyzerTest method testSandboxIssue.

@Test
public void testSandboxIssue() throws Exception {
    // First, get a TestCase from a carved JUnit
    Properties.SELECTED_JUNIT = com.examples.with.different.packagename.sandbox.OpenStreamInATryCatch_FakeTestToCarve.class.getCanonicalName();
    Properties.TARGET_CLASS = com.examples.with.different.packagename.sandbox.OpenStreamInATryCatch.class.getCanonicalName();
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH };
    Properties.SEED_MUTATIONS = 0;
    Properties.SEED_CLONE = 1;
    Properties.VIRTUAL_FS = false;
    Properties.SANDBOX = true;
    // needed for setLoggingForJUnit
    Properties.ENABLE_ASSERTS_FOR_EVOSUITE = true;
    Properties.TEST_SCAFFOLDING = false;
    // FIXME
    Sandbox.initializeSecurityManagerForSUT();
    // file should never be created
    Assert.assertFalse(file.exists());
    JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory(null);
    TestChromosome carved = factory.getChromosome();
    /*
		 * FIXME: issue with carver
		 */
    Files.deleteIfExists(file.toPath());
    Assert.assertFalse(file.exists());
    Assert.assertNotNull(carved);
    TestCase test = carved.getTestCase();
    Assert.assertEquals("Should be: constructor, 1 variable and 1 method", 3, test.size());
    // Now that we have a test case, we check its execution after
    // recompiling it to JUnit, and see if sandbox kicks in
    List<TestCase> list = new ArrayList<TestCase>();
    list.add(test);
    Assert.assertFalse(file.exists());
    // NOTE: following order of checks reflects what is done
    // in EvoSuite after the search is finished
    System.out.println("\n COMPILATION CHECK \n");
    // first try to compile (which implies execution)
    JUnitAnalyzer.removeTestsThatDoNotCompile(list);
    Assert.assertEquals(1, list.size());
    Assert.assertFalse(file.exists());
    System.out.println("\n FIRST STABILITY CHECK \n");
    // try once
    JUnitAnalyzer.handleTestsThatAreUnstable(list);
    Assert.assertEquals(1, list.size());
    Assert.assertFalse(file.exists());
    System.out.println("\n SECOND STABILITY CHECK \n");
    // try again
    JUnitAnalyzer.handleTestsThatAreUnstable(list);
    Assert.assertEquals(1, list.size());
    Assert.assertFalse(file.exists());
    System.out.println("\n FINAL VERIFICATION \n");
    JUnitAnalyzer.verifyCompilationAndExecution(list);
    Assert.assertEquals(1, list.size());
    Assert.assertFalse(file.exists());
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) TestCase(org.evosuite.testcase.TestCase) ArrayList(java.util.ArrayList) Properties(org.evosuite.Properties) TestChromosome(org.evosuite.testcase.TestChromosome) Test(org.junit.Test)

Example 4 with JUnitTestCarvedChromosomeFactory

use of org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory in project evosuite by EvoSuite.

the class JUnitTestCarvedChromosomeFactorySystemTest method testGenericClassTwoParameter.

@Test
public void testGenericClassTwoParameter() {
    Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.GenericObjectWrapperTwoParameterTest.class.getCanonicalName();
    Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.GenericObjectWrapperTwoParameter.class.getCanonicalName();
    Properties.SEED_MUTATIONS = 1;
    Properties.SEED_CLONE = 1;
    JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory(null);
    Assert.assertTrue(factory.hasCarvedTestCases());
    TestChromosome carved = factory.getChromosome();
    Assert.assertNotNull(carved);
    Assert.assertEquals("", 8, carved.test.size());
    for (int i = 0; i < carved.test.size(); i++) {
        Statement stmt = carved.test.getStatement(i);
        boolean valid = stmt.isValid();
        Assert.assertTrue("Invalid stmt at position " + i, valid);
    }
    String code = carved.toString();
    String setLong = "GenericObjectWrapperTwoParameter<String, String>";
    Assert.assertTrue("generated code does not contain " + setLong + "\n" + code, code.contains(setLong));
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) Statement(org.evosuite.testcase.statements.Statement) Test(org.junit.Test)

Example 5 with JUnitTestCarvedChromosomeFactory

use of org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory in project evosuite by EvoSuite.

the class JUnitTestCarvedChromosomeFactorySystemTest method testGenericClassSequence.

@Test
public void testGenericClassSequence() {
    Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.GenericObjectWrapperSequenceTest.class.getCanonicalName();
    Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.GenericObjectWrapper.class.getCanonicalName();
    Properties.SEED_MUTATIONS = 1;
    Properties.SEED_CLONE = 1;
    JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory(null);
    Assert.assertTrue(factory.hasCarvedTestCases());
    TestChromosome carved = factory.getChromosome();
    Assert.assertNotNull(carved);
    Assert.assertEquals("", 6, carved.test.size());
    for (int i = 0; i < carved.test.size(); i++) {
        Statement stmt = carved.test.getStatement(i);
        boolean valid = stmt.isValid();
        Assert.assertTrue("Invalid stmt at position " + i, valid);
    }
    String code = carved.toString();
    String setLong = "GenericObjectWrapper<GenericObjectWrapperSequenceTest.Foo>";
    Assert.assertTrue("generated code does not contain " + setLong + "\n" + code, code.contains(setLong));
    code = carved.toString();
    setLong = "(Object)";
    Assert.assertFalse("generated code contains object cast " + setLong + "\n" + code, code.contains(setLong));
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) Statement(org.evosuite.testcase.statements.Statement) Test(org.junit.Test)

Aggregations

JUnitTestCarvedChromosomeFactory (org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory)41 Test (org.junit.Test)38 Statement (org.evosuite.testcase.statements.Statement)8 Properties (org.evosuite.Properties)2 ArchiveTestChromosomeFactory (org.evosuite.ga.archive.ArchiveTestChromosomeFactory)2 AllMethodsTestChromosomeFactory (org.evosuite.testcase.factories.AllMethodsTestChromosomeFactory)2 RandomLengthTestFactory (org.evosuite.testcase.factories.RandomLengthTestFactory)2 MethodWithSeveralInputArguments (com.examples.with.different.packagename.coverage.MethodWithSeveralInputArguments)1 TestMethodWithSeveralInputArguments (com.examples.with.different.packagename.coverage.TestMethodWithSeveralInputArguments)1 ArrayList (java.util.ArrayList)1 Criterion (org.evosuite.Properties.Criterion)1 TestFitnessFactory (org.evosuite.coverage.TestFitnessFactory)1 FitnessFunction (org.evosuite.ga.FitnessFunction)1 RegressionTestSuiteChromosomeFactory (org.evosuite.regression.RegressionTestSuiteChromosomeFactory)1 CarvedTestCase (org.evosuite.testcarver.testcase.CarvedTestCase)1 TestCase (org.evosuite.testcase.TestCase)1 TestChromosome (org.evosuite.testcase.TestChromosome)1 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)1 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)1 SerializationSuiteChromosomeFactory (org.evosuite.testsuite.factories.SerializationSuiteChromosomeFactory)1