Search in sources :

Example 41 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class ObjectPoolSystemTest method testDifficultClassWithWrongPoolFails.

@Ignore
@Test
public void testDifficultClassWithWrongPoolFails() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = DifficultClassWithoutCarving.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.P_OBJECT_POOL = 0.8;
    Properties.CARVE_OBJECT_POOL = true;
    Properties.SELECTED_JUNIT = ArrayConverterTestCase.class.getCanonicalName();
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    Assert.assertTrue("Did not expect optimal coverage: ", best.getCoverage() < 1d);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) ArrayConverterTestCase(com.examples.with.different.packagename.testcarver.ArrayConverterTestCase) Ignore(org.junit.Ignore) Test(org.junit.Test) DifficultClassTest(com.examples.with.different.packagename.testcarver.DifficultClassTest) DifficultClassWithoutCarvingTest(com.examples.with.different.packagename.testcarver.DifficultClassWithoutCarvingTest)

Example 42 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class TypeSeedingSystemTest method testTypeExampleOff.

@Test
public void testTypeExampleOff() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = TypeExample.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SEED_TYPES = false;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    int goals = TestSuiteGenerator.getFitnessFactories().get(0).getCoverageGoals().size();
    Assert.assertEquals("Wrong number of goals: ", 4, goals);
    Assert.assertTrue("Did not expect optimal coverage: ", best.getCoverage() < 1d);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 43 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class TypeSeedingSystemTest method testObjectToStringCase.

@Test
public void testObjectToStringCase() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ObjectCastExample.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SEED_TYPES = true;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 44 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class BIMutatedMethodSeedingTestSuiteChromosomeFactorySystemTest method testBIMutatedMethod.

@Test
public void testBIMutatedMethod() {
    // probability is SEED_PROBABILITY/test cases, so 10 guarentees a seed
    Properties.SEED_PROBABILITY = 10;
    // Test requires configured test cluster otherwise
    Properties.SEED_MUTATIONS = 0;
    BIMutatedMethodSeedingTestSuiteChromosomeFactory factory = new BIMutatedMethodSeedingTestSuiteChromosomeFactory(defaultFactory, bestIndividual);
    TestSuiteChromosome chromosome = factory.getChromosome();
    boolean containsMutatedSeededMethod = false;
    for (TestCase t : chromosome.getTests()) {
        for (TestCase t2 : bestIndividual.getTests()) {
            if (!t.equals(t2) && !t.equals(TestSampleFactory.CHROMOSOME)) {
                // test case not from original BI or from sample factory,
                // so must be seeded mutated BI
                containsMutatedSeededMethod = true;
            }
        }
    }
    assertTrue(containsMutatedSeededMethod);
}
Also used : TestCase(org.evosuite.testcase.TestCase) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 45 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class InjectionSystemTest method doTest.

private void doTest(Class<?> target) {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = target.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE };
    Properties.JEE = true;
    Properties.P_REFLECTION_ON_PRIVATE = 0.0;
    // Takes extra time to set up the DBManager which is useless
    Properties.ASSERTIONS = false;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Properties(org.evosuite.Properties)

Aggregations

TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)536 Test (org.junit.Test)430 EvoSuite (org.evosuite.EvoSuite)392 Properties (org.evosuite.Properties)78 OutputVariable (org.evosuite.statistics.OutputVariable)50 GenericSUTString (com.examples.with.different.packagename.generic.GenericSUTString)49 TestChromosome (org.evosuite.testcase.TestChromosome)47 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)44 TestCase (org.evosuite.testcase.TestCase)43 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)30 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)22 Ignore (org.junit.Ignore)19 ArrayList (java.util.ArrayList)17 DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)17 TestSuiteFitnessFunction (org.evosuite.testsuite.TestSuiteFitnessFunction)14 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)13 LineCoverageSuiteFitness (org.evosuite.coverage.line.LineCoverageSuiteFitness)13 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)13 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)10 Method (java.lang.reflect.Method)9