Search in sources :

Example 6 with EvoSuite

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

the class DefUseAnalysisSystemTest method testSimpleExample.

@Test
public void testSimpleExample() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = DefUseExample1.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    // Need to deactivate assertions, otherwise classloader is chanaged
    // and DefUseCoverageFactory is reset
    Properties.ASSERTIONS = false;
    // Properties.ANALYSIS_CRITERIA = "Branch,DefUse";
    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(0, DefUseCoverageFactory.getInterMethodGoalsCount());
    Assert.assertEquals(0, DefUseCoverageFactory.getIntraClassGoalsCount());
    Assert.assertEquals(1, DefUseCoverageFactory.getParamGoalsCount());
    Assert.assertEquals(3, DefUseCoverageFactory.getIntraMethodGoalsCount());
    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 7 with EvoSuite

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

the class DefUseAnalysisSystemTest method testGCDExample.

@Test
public void testGCDExample() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = GCD.class.getCanonicalName();
    Properties.ASSERTIONS = false;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    System.out.println("Def: " + DefUsePool.getDefCounter());
    // DefUseCoverageFactory.computeGoals();
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    Assert.assertEquals(0, DefUseCoverageFactory.getInterMethodGoalsCount());
    Assert.assertEquals(0, DefUseCoverageFactory.getIntraClassGoalsCount());
    // 3 or 4?
    Assert.assertEquals(4, DefUseCoverageFactory.getParamGoalsCount());
    Assert.assertEquals(6, DefUseCoverageFactory.getIntraMethodGoalsCount());
    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 8 with EvoSuite

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

the class ImplicitExplicitExceptionsSystemTest method testExceptionFitness.

private void testExceptionFitness() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ImplicitExplicitException.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Properties.Criterion.EXCEPTION };
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.Explicit_MethodExceptions + "," + RuntimeVariable.Explicit_TypeExceptions + "," + RuntimeVariable.Implicit_MethodExceptions + "," + RuntimeVariable.Implicit_TypeExceptions;
    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);
    double fitness = best.getFitness();
    /*
		 * there are 2 undeclared exceptions (both implicit and explicit),
		 * and 3 declared: so fit = 1 / (1+5)
		 */
    Assert.assertEquals("Wrong fitness: ", 1d / 6d, fitness, 0.0000001);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    Assert.assertEquals(1, map.get(RuntimeVariable.Explicit_MethodExceptions.toString()).getValue());
    Assert.assertEquals(1, map.get(RuntimeVariable.Explicit_TypeExceptions.toString()).getValue());
    Assert.assertEquals(1, map.get(RuntimeVariable.Implicit_MethodExceptions.toString()).getValue());
    Assert.assertEquals(1, map.get(RuntimeVariable.Implicit_TypeExceptions.toString()).getValue());
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable)

Example 9 with EvoSuite

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

the class InputCoverageFitnessFunctionSystemTest method testInputCoverage.

@Test
public void testInputCoverage() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = MethodWithSeveralInputArguments.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.MAX_ARRAY = 2;
    Properties.NULL_PROBABILITY = 0.2;
    Properties.SEARCH_BUDGET = 20000;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    List<?> goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals();
    Assert.assertEquals(12, goals.size());
    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 10 with EvoSuite

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

the class MethodCoverageFitnessFunctionSystemTest method testMethodFitnessSimpleExample.

public void testMethodFitnessSimpleExample() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = SingleMethod.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);
    // assuming single fitness function
    int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
    Assert.assertEquals(2, goals);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

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