Search in sources :

Example 36 with EvoSuite

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

the class CoverageAnalysisWithRefectionSystemTest method testBindFilteredEventsToMethod.

@Test
public void testBindFilteredEventsToMethod() throws IOException {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ClassPublicInterface.class.getCanonicalName();
    String testClass = ClassPublicInterfaceTest.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE };
    Properties.OUTPUT_VARIABLES = RuntimeVariable.Total_Goals + "," + RuntimeVariable.LineCoverage;
    Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
    Properties.COVERAGE_MATRIX = true;
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-measureCoverage" };
    SearchStatistics statistics = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(statistics);
    Map<String, OutputVariable<?>> outputVariables = statistics.getOutputVariables();
    // The number of lines seems to be different depending on the compiler
    assertTrue(27 - ((Integer) outputVariables.get(RuntimeVariable.Total_Goals.name()).getValue()) <= 1);
    assertTrue(11 - ((Integer) outputVariables.get(RuntimeVariable.Covered_Goals.name()).getValue()) <= 1);
    assertEquals(1, (Integer) outputVariables.get(RuntimeVariable.Tests_Executed.name()).getValue(), 0.0);
    // Assert that all test cases have passed
    String matrix_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "data" + File.separator + targetClass + File.separator + Properties.Criterion.LINE.name() + File.separator + Properties.COVERAGE_MATRIX_FILENAME;
    System.out.println("matrix_file: " + matrix_file);
    List<String> lines = Files.readAllLines(FileSystems.getDefault().getPath(matrix_file));
    assertTrue(lines.size() == 1);
    assertTrue(lines.get(0).replace(" ", "").endsWith("+"));
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) ClassHierarchyIncludingInterfacesTest(com.examples.with.different.packagename.ClassHierarchyIncludingInterfacesTest) ClassPublicInterfaceTest(com.examples.with.different.packagename.ClassPublicInterfaceTest) ClassWithPrivateInterfacesTest(com.examples.with.different.packagename.ClassWithPrivateInterfacesTest) Test(org.junit.Test)

Example 37 with EvoSuite

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

the class CoverageAnalysisWithRefectionSystemTest method testGetAllInterfaces.

@Test
public void testGetAllInterfaces() throws IOException {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ClassWithPrivateInterfaces.class.getCanonicalName();
    String testClass = ClassWithPrivateInterfacesTest.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE };
    Properties.OUTPUT_VARIABLES = RuntimeVariable.Total_Goals + "," + RuntimeVariable.LineCoverage;
    Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
    Properties.COVERAGE_MATRIX = true;
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-measureCoverage" };
    Object statistics = evosuite.parseCommandLine(command);
    Assert.assertNotNull(statistics);
    // Assert coverage
    String statistics_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "statistics.csv";
    System.out.println("statistics_file: " + statistics_file);
    CSVReader reader = new CSVReader(new FileReader(statistics_file));
    List<String[]> rows = reader.readAll();
    assertTrue(rows.size() == 2);
    reader.close();
    assertEquals("14", CsvJUnitData.getValue(rows, RuntimeVariable.Total_Goals.name()));
    assertEquals(0.93, Double.valueOf(CsvJUnitData.getValue(rows, RuntimeVariable.LineCoverage.name())), 0.01);
    // Assert that all test cases have passed
    String matrix_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "data" + File.separator + targetClass + File.separator + Properties.Criterion.LINE.name() + File.separator + Properties.COVERAGE_MATRIX_FILENAME;
    System.out.println("matrix_file: " + matrix_file);
    List<String> lines = Files.readAllLines(FileSystems.getDefault().getPath(matrix_file));
    assertTrue(lines.size() == 1);
    // number of goals + test result ('+' pass, '-' fail)
    assertEquals(13 + 1 + 1, lines.get(0).replace(" ", "").length());
    assertTrue(lines.get(0).replace(" ", "").endsWith("+"));
}
Also used : CSVReader(com.opencsv.CSVReader) EvoSuite(org.evosuite.EvoSuite) FileReader(java.io.FileReader) Properties(org.evosuite.Properties) ClassHierarchyIncludingInterfacesTest(com.examples.with.different.packagename.ClassHierarchyIncludingInterfacesTest) ClassPublicInterfaceTest(com.examples.with.different.packagename.ClassPublicInterfaceTest) ClassWithPrivateInterfacesTest(com.examples.with.different.packagename.ClassWithPrivateInterfacesTest) Test(org.junit.Test)

Example 38 with EvoSuite

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

the class CookieSystemTest method testZ3DSE.

@Test
public void testZ3DSE() {
    if (System.getenv("z3_path") == null) {
        System.out.println("z3_path should be configured for running this test case");
        return;
    }
    Properties.Z3_PATH = System.getenv("z3_path");
    Properties.DSE_SOLVER = SolverType.Z3_SOLVER;
    Properties.STOPPING_CONDITION = StoppingCondition.MAXTIME;
    Properties.SEARCH_BUDGET = 120;
    // should it be trivial for DSE ?
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Cookie.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Criterion.LINE, Criterion.BRANCH, Criterion.EXCEPTION, Criterion.WEAKMUTATION, Criterion.OUTPUT, Criterion.METHOD, Criterion.METHODNOEXCEPTION, Criterion.CBRANCH };
    Properties.MINIMIZE = false;
    Properties.ASSERTIONS = false;
    // force using only DSE, no LS
    Properties.DSE_PROBABILITY = 1.0;
    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);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 39 with EvoSuite

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

the class DseWithUrlSystemTest method testDSE.

@Test
public void testDSE() {
    Properties.DSE_SOLVER = SolverType.EVOSUITE_SOLVER;
    Properties.STOPPING_CONDITION = StoppingCondition.MAXTIME;
    Properties.SEARCH_BUDGET = 120;
    // should it be trivial for DSE ?
    EvoSuite evosuite = new EvoSuite();
    String targetClass = DseWithURL.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Criterion.BRANCH, Criterion.EXCEPTION };
    Properties.MINIMIZE = true;
    Properties.ASSERTIONS = true;
    // force using only DSE, no LS
    Properties.DSE_PROBABILITY = 1.0;
    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);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 40 with EvoSuite

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

the class ExampleHardForGASystemTest method testZ3.

@Test
public void testZ3() {
    Assume.assumeTrue(System.getenv("z3_path") != null);
    Properties.Z3_PATH = System.getenv("z3_path");
    Properties.DSE_SOLVER = SolverType.Z3_SOLVER;
    Properties.LOCAL_SEARCH_PROBABILITY = 1.0;
    Properties.LOCAL_SEARCH_RATE = 8;
    Properties.LOCAL_SEARCH_BUDGET_TYPE = Properties.LocalSearchBudgetType.TESTS;
    Properties.LOCAL_SEARCH_BUDGET = 10;
    // force using only DSE, no LS
    Properties.DSE_PROBABILITY = 1.0;
    Properties.CONCOLIC_TIMEOUT = 1000;
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ExampleHardForGA.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    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) 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