Search in sources :

Example 1 with EvoSuite

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

the class SearchStatisticsSystemTest method testGradientBranchesOutputVariable.

@Test
public void testGradientBranchesOutputVariable() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ExampleGradientBranches.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.DYNAMIC_SEEDING = true;
    Properties.SEARCH_BUDGET = 2500;
    Properties.TRACK_BOOLEAN_BRANCHES = true;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.Coverage + "," + RuntimeVariable.Gradient_Branches;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    evosuite.parseCommandLine(command);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable<?> coverage = map.get(RuntimeVariable.Coverage.toString());
    Assert.assertNotNull(coverage);
    Assert.assertEquals(1.0, coverage.getValue());
    OutputVariable<?> gradientBranches = map.get(RuntimeVariable.Gradient_Branches.toString());
    Assert.assertNotNull(gradientBranches);
    Assert.assertEquals(4, gradientBranches.getValue());
}
Also used : EvoSuite(org.evosuite.EvoSuite) Test(org.junit.Test)

Example 2 with EvoSuite

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

the class SearchStatisticsSystemTest method testHandlingOfNoThreads.

@Test
public void testHandlingOfNoThreads() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = NoThreads.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SANDBOX = true;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.Threads;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    evosuite.parseCommandLine(command);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable<?> threads = map.get(RuntimeVariable.Threads.toString());
    Assert.assertNotNull(threads);
    Assert.assertEquals(1, threads.getValue());
}
Also used : EvoSuite(org.evosuite.EvoSuite) Test(org.junit.Test)

Example 3 with EvoSuite

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

the class SearchStatisticsSystemTest method testHandlingOfMultiThreads.

// ignored due to problems of JVM8 crashing on MacOS, and anyway we do not really need to check for threads any more
@Ignore
@Test
public void testHandlingOfMultiThreads() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = MultiThreads.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SANDBOX = true;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.Threads;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    evosuite.parseCommandLine(command);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable<?> threads = map.get(RuntimeVariable.Threads.toString());
    Assert.assertNotNull(threads);
    Assert.assertEquals(3, threads.getValue());
// TODO: This test currently fails because MSecurityManager does not set the number
// of threads correctly to avoid a JVM8 crash on MacOS:
// PermissionStatistics.getInstance().countThreads(Thread.currentThread().getThreadGroup().activeCount());
}
Also used : EvoSuite(org.evosuite.EvoSuite) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with EvoSuite

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

the class FactoryTestSystemTest method setupCluster.

@Before
public void setupCluster() {
    EvoSuite evosuite = new EvoSuite();
    // Archive will remove test calls,
    // invalidating testTestCalls
    Properties.TEST_ARCHIVE = false;
    String targetClass = FactoryExample.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    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);
}
Also used : EvoSuite(org.evosuite.EvoSuite) Before(org.junit.Before)

Example 5 with EvoSuite

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

the class JUnitTestCarvedChromosomeFactorySystemTest method testDifficultClassWithWrongTestFails.

// EvoSuite may also cover it without seeding now.
@Ignore
@Test
public void testDifficultClassWithWrongTestFails() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = DifficultClassWithoutCarving.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.TEST_FACTORY = TestFactory.JUNIT;
    Properties.SELECTED_JUNIT = DifficultClassTest.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) Ignore(org.junit.Ignore) 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