Search in sources :

Example 91 with TestSuiteChromosome

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

the class MockJOptionPaneSystemTest method testShowInputMultipleDialogs.

@Test
public void testShowInputMultipleDialogs() throws Exception {
    final String targetClass = AskUserShowInputDailogs.class.getCanonicalName();
    Properties.TEST_ARCHIVE = false;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH };
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_GUI = true;
    Properties.MINIMIZE = true;
    // As mutation operators remove instrumentation. This needs fixing first
    Properties.ASSERTIONS = false;
    EvoSuite evosuite = new EvoSuite();
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    Assert.assertNotNull(best);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
    Assert.assertEquals("Non-optimal fitness: ", 0d, best.getFitness(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Properties(org.evosuite.Properties) Test(org.junit.Test)

Example 92 with TestSuiteChromosome

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

the class MockJOptionPaneSystemTest method testShowConfirmDialogs0.

@Test
public void testShowConfirmDialogs0() throws Exception {
    final String targetClass = AskUserShowConfirmDialogs0.class.getCanonicalName();
    Properties.TEST_ARCHIVE = false;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH };
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_GUI = true;
    Properties.MINIMIZE = true;
    // As mutation operators remove instrumentation. This needs fixing first
    Properties.ASSERTIONS = false;
    EvoSuite evosuite = new EvoSuite();
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    Assert.assertNotNull(best);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
    Assert.assertEquals("Non-optimal fitness: ", 0d, best.getFitness(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Properties(org.evosuite.Properties) Test(org.junit.Test)

Example 93 with TestSuiteChromosome

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

the class MockJOptionPaneSystemTest method testShowConfirmDialogs3.

@Test
public void testShowConfirmDialogs3() throws Exception {
    final String targetClass = AskUserShowConfirmDialogs3.class.getCanonicalName();
    Properties.TEST_ARCHIVE = false;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH };
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_GUI = true;
    Properties.MINIMIZE = true;
    // As mutation operators remove instrumentation. This needs fixing first
    Properties.ASSERTIONS = false;
    EvoSuite evosuite = new EvoSuite();
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    Assert.assertNotNull(best);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
    Assert.assertEquals("Non-optimal fitness: ", 0d, best.getFitness(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Properties(org.evosuite.Properties) Test(org.junit.Test)

Example 94 with TestSuiteChromosome

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

the class GeneratedFilesEvenWithSandboxSystemTest method testCreateWithNoCatch.

@Test
public void testCreateWithNoCatch() {
    Assert.assertFalse(file.exists());
    EvoSuite evosuite = new EvoSuite();
    String targetClass = OpenStream.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SANDBOX = true;
    Properties.JUNIT_TESTS = true;
    Properties.VIRTUAL_FS = false;
    Properties.JUNIT_CHECK_ON_SEPARATE_PROCESS = false;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    // assuming single fitness function
    int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
    Assert.assertEquals("Wrong number of goals: ", 3, goals);
    Assert.assertTrue("Should not achieve optimal coverage ", best.getCoverage() < 1);
    // SUT should not generate the file
    Assert.assertFalse(file.exists());
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 95 with TestSuiteChromosome

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

the class NumericDynamicSeedingSystemTest method testDynamicSeedingDouble.

// DOUBLES
@Test
public void testDynamicSeedingDouble() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = NumericDynamicDoubleSeeding.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CLIENT_ON_THREAD = true;
    Properties.DYNAMIC_SEEDING = true;
    // Properties.ALGORITHM = Properties.Algorithm.ONEPLUSONEEA;
    // Probability of picking value from constants pool
    Properties.DYNAMIC_POOL = 0.8d;
    ConstantPoolManager.getInstance().reset();
    String[] command = new String[] { "-generateSuite", "-class", targetClass, "-Dprint_to_system=true" };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    System.out.println("ConstantPool:\n" + ConstantPoolManager.getInstance().getDynamicConstantPool().toString());
    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)

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