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);
}
}
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);
}
}
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());
}
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));
}
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));
}
Aggregations