Search in sources :

Example 36 with JUnitTestCarvedChromosomeFactory

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

the class JUnitTestCarvedChromosomeFactorySystemTest method testJavaAgent.

@Test
public void testJavaAgent() {
    Properties.SELECTED_JUNIT = PersonWithJavaAgentSystemTest.class.getCanonicalName();
    Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.Person.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);
    String code = carved.toString();
    Assert.assertEquals(code, 3, carved.test.size());
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) Test(org.junit.Test)

Example 37 with JUnitTestCarvedChromosomeFactory

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

the class JUnitTestCarvedChromosomeFactorySystemTest method testReadPublicField.

@Test
public void testReadPublicField() {
    Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.ClassWithPublicFieldReadingTestCase.class.getCanonicalName();
    Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.ClassWithPublicField.class.getCanonicalName();
    Properties.SEED_MUTATIONS = 0;
    Properties.SEED_CLONE = 1;
    JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory(null);
    Assert.assertEquals(1, factory.getNumCarvedTestCases());
    TestChromosome test = factory.getChromosome();
    String code = test.getTestCase().toCode();
    System.out.println(code);
    Assert.assertFalse(code.contains("XStream"));
    Assert.assertTrue(code.contains("classWithPublicField0.x") || code.contains("Locale.CHINESE"));
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) Test(org.junit.Test)

Example 38 with JUnitTestCarvedChromosomeFactory

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

the class JUnitTestCarvedChromosomeFactorySystemTest method testBeanDateConverterUtils2.

@Test
public void testBeanDateConverterUtils2() {
    Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.DateConverterTest2.class.getCanonicalName();
    Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.DateConverter.class.getCanonicalName();
    Properties.SEED_MUTATIONS = 1;
    Properties.SEED_CLONE = 1;
    JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory(null);
    Assert.assertEquals(1, factory.getNumCarvedTestCases());
    String code = factory.getChromosome().getTestCase().toCode();
    System.out.println(code);
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) Test(org.junit.Test)

Example 39 with JUnitTestCarvedChromosomeFactory

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

the class JUnitTestCarvedChromosomeFactorySystemTest method testGenericClassArray.

@Test
public void testGenericClassArray() {
    Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.GenericObjectWrapperArrayTest.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("", 13, 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<Long[]>";
    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 40 with JUnitTestCarvedChromosomeFactory

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

the class JUnitTestCarvedChromosomeFactorySystemTest method testBeanDateConverterUtils11.

@Test
public void testBeanDateConverterUtils11() {
    Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.DateConverterTest11.class.getCanonicalName();
    Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.DateConverter.class.getCanonicalName();
    Properties.SEED_MUTATIONS = 1;
    Properties.SEED_CLONE = 1;
    JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory(null);
    Assert.assertEquals(1, factory.getNumCarvedTestCases());
    String code = factory.getChromosome().getTestCase().toCode();
    System.out.println(code);
}
Also used : JUnitTestCarvedChromosomeFactory(org.evosuite.testcase.factories.JUnitTestCarvedChromosomeFactory) 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