Search in sources :

Example 21 with EvoSuite

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

the class CurrentTimeSystemTest method testTimeOperation.

@Test
public void testTimeOperation() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = TimeOperation.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_CALLS = true;
    // , "-assertions"
    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.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 22 with EvoSuite

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

the class SUTWithSystemExitSystemTest method testSystemExit.

@Test
public void testSystemExit() {
    java.lang.System.setSecurityManager(new SafeExit());
    EvoSuite evosuite = new EvoSuite();
    String targetClass = CallExit.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_CALLS = true;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    evosuite.parseCommandLine(command);
    assertFalse(SafeExit.calledExit);
}
Also used : EvoSuite(org.evosuite.EvoSuite) Test(org.junit.Test)

Example 23 with EvoSuite

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

the class IssueStaticInitializerWithTryCatchSystemTest method runTheTest.

private void runTheTest(boolean reset) {
    Properties.RESET_STATIC_FIELDS = reset;
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ClassWithStaticInitializerTryCatch.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();
    Assert.assertNotNull(best);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

Example 24 with EvoSuite

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

the class DeleteFileSystemTest method testDeleteOnThread.

@Test
public void testDeleteOnThread() throws IOException {
    String tmpdir = System.getProperty("java.io.tmpdir");
    File toDelete = new File(tmpdir + File.separator + "this_file_should_not_be_deleted_by_evosuite");
    FileUtils.write(toDelete, "BlahBlah");
    assertTrue(toDelete.exists());
    EvoSuite evosuite = new EvoSuite();
    String targetClass = DeleteFileThread.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SANDBOX = true;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    evosuite.parseCommandLine(command);
    assertTrue("File has been deleted: " + toDelete.getAbsolutePath(), toDelete.exists());
    toDelete.delete();
}
Also used : EvoSuite(org.evosuite.EvoSuite) File(java.io.File) Test(org.junit.Test)

Example 25 with EvoSuite

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

the class DeleteFileSystemTest method testDeleteStaticNoReset.

@Test
public void testDeleteStaticNoReset() throws IOException {
    Properties.RESET_STATIC_FIELDS = false;
    String tmpdir = System.getProperty("java.io.tmpdir");
    File toDelete = new File(tmpdir + File.separator + "this_file_should_not_be_deleted_by_evosuite");
    FileUtils.write(toDelete, "BlahBlah");
    assertTrue(toDelete.exists());
    EvoSuite evosuite = new EvoSuite();
    String targetClass = DeleteInStaticInitializer.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SANDBOX = true;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    evosuite.parseCommandLine(command);
    assertTrue("File has been deleted: " + toDelete.getAbsolutePath(), toDelete.exists());
    toDelete.delete();
}
Also used : EvoSuite(org.evosuite.EvoSuite) File(java.io.File) 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