Search in sources :

Example 61 with TestSuiteChromosome

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

the class StandardChemicalReactionSystemTest method testIntermolecularIneffectiveCollision.

@Test
public void testIntermolecularIneffectiveCollision() {
    GeneticAlgorithm<?> ga = test(1.0, -1, -1);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    Assert.assertEquals(6, best.getNumOfCoveredGoals());
    Assert.assertEquals(6.0 / 9.0, best.getCoverage(), 0.001);
}
Also used : TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 62 with TestSuiteChromosome

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

the class StandardChemicalReactionSystemTest method testSynthesis.

@Test
public void testSynthesis() {
    GeneticAlgorithm<?> ga = test(1.0, -1, 1_000_000);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    Assert.assertEquals(7, best.getNumOfCoveredGoals());
    Assert.assertEquals(7.0 / 9.0, best.getCoverage(), 0.001);
}
Also used : TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 63 with TestSuiteChromosome

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

the class LambdaInStaticConstructorSystemTest method testNoCrashInCLINIT.

@Test
public void testNoCrashInCLINIT() throws Throwable {
    String targetClass = LambdaInStaticConstructor.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.TIMEOUT = 50000000;
    Properties.RESET_STATIC_FINAL_FIELDS = true;
    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();
    System.out.println(best.toString());
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 64 with TestSuiteChromosome

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

the class AbstractErrorBranchTest method checkErrorBranches.

protected void checkErrorBranches(Class<?> targetClass, int realBranches, int instrumentedBranches, int coveredRealBranches, int coveredInstrumentedBranches) {
    TestSuiteChromosome best = runEvoSuite(targetClass);
    assertBranchStats(realBranches, instrumentedBranches, coveredRealBranches, coveredInstrumentedBranches);
    Assert.assertEquals(realBranches, TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size());
    Assert.assertEquals(instrumentedBranches, TestGenerationStrategy.getFitnessFactories().get(1).getCoverageGoals().size());
    double meanCoverage = 0.0;
    if (instrumentedBranches > 0) {
        meanCoverage += (double) coveredInstrumentedBranches / instrumentedBranches;
    } else {
        meanCoverage += 1.0;
    }
    if (realBranches > 0) {
        meanCoverage += (double) coveredRealBranches / realBranches;
    } else {
        meanCoverage += 1.0;
    }
    meanCoverage /= 2.0;
    Assert.assertEquals("Non-optimal coverage: ", meanCoverage, best.getCoverage(), 0.001);
}
Also used : TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

Example 65 with TestSuiteChromosome

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

the class AbstractErrorBranchTest method runEvoSuite.

private TestSuiteChromosome runEvoSuite(Class<?> targetClass) {
    EvoSuite evosuite = new EvoSuite();
    String targetClassName = targetClass.getCanonicalName();
    Properties.TARGET_CLASS = targetClassName;
    Properties.ASSERTIONS = false;
    Properties.JUNIT_TESTS = false;
    Properties.JUNIT_CHECK = false;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, Properties.Criterion.TRYCATCH };
    String[] command = new String[] { "-generateSuite", "-class", targetClassName };
    StringBuilder s = new StringBuilder();
    s.append(RuntimeVariable.Coverage);
    s.append(",");
    s.append(RuntimeVariable.BranchCoverage);
    s.append(",");
    s.append(RuntimeVariable.Covered_Goals);
    s.append(",");
    s.append(RuntimeVariable.Total_Goals);
    s.append(",");
    s.append(RuntimeVariable.Covered_Branches);
    s.append(",");
    s.append(RuntimeVariable.Covered_Branchless_Methods);
    s.append(",");
    s.append(RuntimeVariable.Covered_Branches_Real);
    s.append(",");
    s.append(RuntimeVariable.Covered_Branches_Instrumented);
    s.append(",");
    Properties.OUTPUT_VARIABLES = s.toString();
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println(best.toString());
    return best;
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Properties(org.evosuite.Properties)

Aggregations

TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)536 Test (org.junit.Test)430 EvoSuite (org.evosuite.EvoSuite)392 Properties (org.evosuite.Properties)78 OutputVariable (org.evosuite.statistics.OutputVariable)50 GenericSUTString (com.examples.with.different.packagename.generic.GenericSUTString)49 TestChromosome (org.evosuite.testcase.TestChromosome)47 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)44 TestCase (org.evosuite.testcase.TestCase)43 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)30 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)22 Ignore (org.junit.Ignore)19 ArrayList (java.util.ArrayList)17 DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)17 TestSuiteFitnessFunction (org.evosuite.testsuite.TestSuiteFitnessFunction)14 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)13 LineCoverageSuiteFitness (org.evosuite.coverage.line.LineCoverageSuiteFitness)13 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)13 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)10 Method (java.lang.reflect.Method)9