Search in sources :

Example 61 with TestCase

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

the class BIMutatedMethodSeedingTestSuiteChromosomeFactorySystemTest method testBIMutatedMethod.

@Test
public void testBIMutatedMethod() {
    // probability is SEED_PROBABILITY/test cases, so 10 guarentees a seed
    Properties.SEED_PROBABILITY = 10;
    // Test requires configured test cluster otherwise
    Properties.SEED_MUTATIONS = 0;
    BIMutatedMethodSeedingTestSuiteChromosomeFactory factory = new BIMutatedMethodSeedingTestSuiteChromosomeFactory(defaultFactory, bestIndividual);
    TestSuiteChromosome chromosome = factory.getChromosome();
    boolean containsMutatedSeededMethod = false;
    for (TestCase t : chromosome.getTests()) {
        for (TestCase t2 : bestIndividual.getTests()) {
            if (!t.equals(t2) && !t.equals(TestSampleFactory.CHROMOSOME)) {
                // test case not from original BI or from sample factory,
                // so must be seeded mutated BI
                containsMutatedSeededMethod = true;
            }
        }
    }
    assertTrue(containsMutatedSeededMethod);
}
Also used : TestCase(org.evosuite.testcase.TestCase) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 62 with TestCase

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

the class LocalSearchNumericSystemTest method runDoubleExample.

private void runDoubleExample(double x, double y) throws ClassNotFoundException, ConstructionFailedException, NoSuchMethodException, SecurityException {
    TestCase test = getDoubleTest(x, y);
    TestSuiteChromosome suite = new TestSuiteChromosome();
    BranchCoverageSuiteFitness fitness = new BranchCoverageSuiteFitness();
    BranchCoverageMap.getInstance().searchStarted(null);
    assertEquals(4.0, fitness.getFitness(suite), 0.1F);
    suite.addTest(test);
    assertEquals(1.0, fitness.getFitness(suite), 0.1F);
    TestSuiteLocalSearch localSearch = TestSuiteLocalSearch.selectTestSuiteLocalSearch();
    LocalSearchObjective<TestSuiteChromosome> localObjective = new DefaultLocalSearchObjective<TestSuiteChromosome>();
    localObjective.addFitnessFunction(fitness);
    localSearch.doSearch(suite, localObjective);
    System.out.println("Fitness: " + fitness.getFitness(suite));
    System.out.println("Test suite: " + suite);
    assertEquals(0.0, fitness.getFitness(suite), 0.1F);
    BranchCoverageMap.getInstance().searchFinished(null);
}
Also used : TestSuiteLocalSearch(org.evosuite.testsuite.localsearch.TestSuiteLocalSearch) DefaultLocalSearchObjective(org.evosuite.ga.localsearch.DefaultLocalSearchObjective) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

Example 63 with TestCase

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

the class RandomMethodSeedingTestSuiteChromosomeFactorySystemTest method testRandomMethod.

@Test
public void testRandomMethod() {
    // probability is SEED_PROBABILITY/test cases, so 10 guarentees a seed
    Properties.SEED_PROBABILITY = 10;
    RandomMethodSeedingTestSuiteChromosomeFactory factory = new RandomMethodSeedingTestSuiteChromosomeFactory(defaultFactory, ga);
    TestSuiteChromosome chromosome = factory.getChromosome();
    boolean containsSeededMethod = false;
    for (TestCase t : chromosome.getTests()) {
        for (TestSuiteChromosome tsc : ga.getPopulation()) {
            for (TestCase t2 : tsc.getTests()) {
                if (t.equals(t2)) {
                    containsSeededMethod = true;
                }
            }
        }
    }
    assertTrue(containsSeededMethod);
}
Also used : TestCase(org.evosuite.testcase.TestCase) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 64 with TestCase

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

the class LIPS method runTest.

/**
 * This method executes a given test case (i.e., TestChromosome)
 *
 * @param c test case (TestChromosome) to execute
 */
protected void runTest(T c) {
    if (!c.isChanged())
        return;
    // run the test
    TestCase test = ((TestChromosome) c).getTestCase();
    ExecutionResult result = TestCaseExecutor.runTest(test);
    ((TestChromosome) c).setLastExecutionResult(result);
    c.setChanged(false);
    // notify the fitness evaluation (i.e., the test is executed)
    notifyEvaluation(c);
}
Also used : TestCase(org.evosuite.testcase.TestCase) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) TestChromosome(org.evosuite.testcase.TestChromosome)

Example 65 with TestCase

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

the class BranchesManager method calculateFitness.

public void calculateFitness(T c) {
    // run the test
    TestCase test = ((TestChromosome) c).getTestCase();
    ExecutionResult result = TestCaseExecutor.runTest(test);
    ((TestChromosome) c).setLastExecutionResult(result);
    c.setChanged(false);
    if (result.hasTimeout() || result.hasTestException()) {
        for (FitnessFunction<T> f : currentGoals) c.setFitness(f, Double.MAX_VALUE);
        return;
    }
    // 1) we update the set of currents goals
    Set<FitnessFunction<T>> visitedStatements = new HashSet<FitnessFunction<T>>(uncoveredGoals.size() * 2);
    LinkedList<FitnessFunction<T>> targets = new LinkedList<FitnessFunction<T>>();
    targets.addAll(this.currentGoals);
    while (targets.size() > 0) {
        FitnessFunction<T> fitnessFunction = targets.poll();
        int past_size = visitedStatements.size();
        visitedStatements.add(fitnessFunction);
        if (past_size == visitedStatements.size())
            continue;
        double value = fitnessFunction.getFitness(c);
        if (value == 0.0) {
            updateCoveredGoals(fitnessFunction, c);
            for (FitnessFunction<T> child : graph.getStructuralChildren(fitnessFunction)) {
                targets.addLast(child);
            }
        } else {
            currentGoals.add(fitnessFunction);
        }
    }
    currentGoals.removeAll(coveredGoals.keySet());
    // 2) we update the archive
    for (Integer branchid : result.getTrace().getCoveredFalseBranches()) {
        FitnessFunction<T> branch = this.branchCoverageFalseMap.get(branchid);
        if (branch == null)
            continue;
        updateCoveredGoals((FitnessFunction<T>) branch, c);
    }
    for (Integer branchid : result.getTrace().getCoveredTrueBranches()) {
        FitnessFunction<T> branch = this.branchCoverageTrueMap.get(branchid);
        if (branch == null)
            continue;
        updateCoveredGoals((FitnessFunction<T>) branch, c);
    }
    for (String method : result.getTrace().getCoveredBranchlessMethods()) {
        FitnessFunction<T> branch = this.branchlessMethodCoverageMap.get(method);
        if (branch == null)
            continue;
        updateCoveredGoals((FitnessFunction<T>) branch, c);
    }
// debugStructuralDependencies(c);
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) FitnessFunction(org.evosuite.ga.FitnessFunction) LinkedList(java.util.LinkedList) TestCase(org.evosuite.testcase.TestCase) TestChromosome(org.evosuite.testcase.TestChromosome) HashSet(java.util.HashSet)

Aggregations

TestCase (org.evosuite.testcase.TestCase)192 Test (org.junit.Test)119 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)90 ArrayList (java.util.ArrayList)67 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)47 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)45 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)43 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)39 VariableReference (org.evosuite.testcase.variable.VariableReference)26 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)25 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)25 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)24 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)17 TestChromosome (org.evosuite.testcase.TestChromosome)17 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)15 Ignore (org.junit.Ignore)15 VariableReferenceImpl (org.evosuite.testcase.variable.VariableReferenceImpl)14 GenericMethod (org.evosuite.utils.generic.GenericMethod)12 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)11 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)10