Search in sources :

Example 26 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.

the class TestDefaultValue method testCharacter.

@Test
public void testCharacter() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    ArrayReference characterArray0 = builder.appendArrayStmt(Character[].class, 10);
    VariableReference character0 = builder.appendNull(Character.class);
    builder.appendAssignment(characterArray0, 0, character0);
    builder.appendAssignment(character0, characterArray0, 0);
    builder.appendMethod(character0, Character.class.getMethod("toString"));
    DefaultTestCase tc = builder.getDefaultTestCase();
    ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
    assertNotNull(ret_val);
    assertFalse(ret_val.explicitExceptions.isEmpty());
}
Also used : ArrayReference(org.evosuite.testcase.variable.ArrayReference) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Test(org.junit.Test)

Example 27 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.

the class TestDefaultValue method testDouble.

@Test
public void testDouble() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    ArrayReference doubleArray0 = builder.appendArrayStmt(Double[].class, 10);
    VariableReference double0 = builder.appendNull(Double.class);
    builder.appendAssignment(doubleArray0, 0, double0);
    builder.appendAssignment(double0, doubleArray0, 0);
    builder.appendMethod(double0, Double.class.getMethod("floatValue"));
    DefaultTestCase tc = builder.getDefaultTestCase();
    ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
    assertNotNull(ret_val);
    assertFalse(ret_val.explicitExceptions.isEmpty());
}
Also used : ArrayReference(org.evosuite.testcase.variable.ArrayReference) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Test(org.junit.Test)

Example 28 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult 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 29 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult 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)

Example 30 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.

the class MIOArchive method updateArchive.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void updateArchive(F target, T solution, double fitnessValue) {
    assert target != null;
    assert this.archive.containsKey(target);
    assert fitnessValue >= 0.0;
    T solutionClone = (T) solution.clone();
    ExecutionResult executionResult = solutionClone.getLastExecutionResult();
    // remove all statements after an exception
    if (!executionResult.noThrownExceptions()) {
        solutionClone.getTestCase().chop(executionResult.getFirstPositionOfThrownException() + 1);
    }
    boolean isNewCoveredTarget = this.archive.get(target).addSolution(1.0 - FitnessFunction.normalize(fitnessValue), solutionClone);
    if (isNewCoveredTarget) {
        this.removeNonCoveredTargetOfAMethod(target);
        this.hasBeenUpdated = true;
    }
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Aggregations

ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)93 TestChromosome (org.evosuite.testcase.TestChromosome)33 HashSet (java.util.HashSet)15 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)15 ArrayList (java.util.ArrayList)11 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)10 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)9 TestCase (org.evosuite.testcase.TestCase)9 VariableReference (org.evosuite.testcase.variable.VariableReference)9 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)7 ArrayReference (org.evosuite.testcase.variable.ArrayReference)7 Set (java.util.Set)6 AbstractTestSuiteChromosome (org.evosuite.testsuite.AbstractTestSuiteChromosome)6 Map (java.util.Map)4 Entry (java.util.Map.Entry)3 ExecutionTrace (org.evosuite.testcase.execution.ExecutionTrace)3