Search in sources :

Example 81 with EvoSuite

use of org.evosuite.EvoSuite 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 82 with EvoSuite

use of org.evosuite.EvoSuite 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 83 with EvoSuite

use of org.evosuite.EvoSuite 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)

Example 84 with EvoSuite

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

the class NumericDynamicSeedingSystemTest method testDynamicSeedingFloat.

// FLOATS
@Test
public void testDynamicSeedingFloat() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = NumericDynamicFloatSeeding.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.8f;
    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)

Example 85 with EvoSuite

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

the class NumericDynamicSeedingSystemTest method testDynamicSeedingLong.

// LONGS
@Test
public void testDynamicSeedingLong() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = NumericDynamicLongSeeding.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.8;
    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

EvoSuite (org.evosuite.EvoSuite)462 Test (org.junit.Test)410 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)391 Properties (org.evosuite.Properties)86 OutputVariable (org.evosuite.statistics.OutputVariable)61 GenericSUTString (com.examples.with.different.packagename.generic.GenericSUTString)49 SearchStatistics (org.evosuite.statistics.SearchStatistics)16 Ignore (org.junit.Ignore)15 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)13 CSVReader (com.opencsv.CSVReader)12 FileReader (java.io.FileReader)12 File (java.io.File)9 TestCase (org.evosuite.testcase.TestCase)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 MethodCoverageFitnessFunctionSystemTest (org.evosuite.coverage.method.MethodCoverageFitnessFunctionSystemTest)7 Before (org.junit.Before)7 TypeSeedingExampleString (com.examples.with.different.packagename.TypeSeedingExampleString)6 TestGenerationResult (org.evosuite.result.TestGenerationResult)6 CalculatorTest (com.examples.with.different.packagename.CalculatorTest)5