Search in sources :

Example 46 with ExecutionResult

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

the class TestDefaultValue method testShort.

@Test
public void testShort() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    ArrayReference integerArray0 = builder.appendArrayStmt(Short[].class, 10);
    VariableReference integer0 = builder.appendNull(Short.class);
    builder.appendAssignment(integerArray0, 0, integer0);
    builder.appendAssignment(integer0, integerArray0, 0);
    builder.appendMethod(integer0, Short.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 47 with ExecutionResult

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

the class TestDefaultValue method testInteger.

@Test
public void testInteger() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    ArrayReference integerArray0 = builder.appendArrayStmt(Integer[].class, 10);
    VariableReference integer0 = builder.appendNull(Integer.class);
    builder.appendAssignment(integerArray0, 0, integer0);
    builder.appendAssignment(integer0, integerArray0, 0);
    builder.appendMethod(integer0, Integer.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 48 with ExecutionResult

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

the class TestDefaultValue method testByte.

@Test
public void testByte() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    ArrayReference integerArray0 = builder.appendArrayStmt(Byte[].class, 10);
    VariableReference integer0 = builder.appendNull(Byte.class);
    builder.appendAssignment(integerArray0, 0, integer0);
    builder.appendAssignment(integer0, integerArray0, 0);
    builder.appendMethod(integer0, Byte.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 49 with ExecutionResult

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

the class AssertionGenerator method runTest.

/**
 * Execute a test case on the original unit
 *
 * @param test
 *            The test case that should be executed
 * @return a {@link org.evosuite.testcase.execution.ExecutionResult} object.
 */
protected ExecutionResult runTest(TestCase test) {
    ExecutionResult result = new ExecutionResult(test);
    try {
        logger.debug("Executing test");
        result = TestCaseExecutor.getInstance().execute(test);
        int num = test.size();
        MaxStatementsStoppingCondition.statementsExecuted(num);
        result.setTrace(comparisonObserver.getTrace(), ComparisonTraceEntry.class);
        result.setTrace(primitiveObserver.getTrace(), PrimitiveTraceEntry.class);
        result.setTrace(inspectorObserver.getTrace(), InspectorTraceEntry.class);
        result.setTrace(fieldObserver.getTrace(), PrimitiveFieldTraceEntry.class);
        result.setTrace(nullObserver.getTrace(), NullTraceEntry.class);
        result.setTrace(sameObserver.getTrace(), SameTraceEntry.class);
        if (!Properties.isRegression())
            result.setTrace(arrayObserver.getTrace(), ArrayTraceEntry.class);
        result.setTrace(arrayLengthObserver.getTrace(), ArrayLengthTraceEntry.class);
        result.setTrace(containsTraceObserver.getTrace(), ContainsTraceEntry.class);
    } catch (Exception e) {
        throw new Error(e);
    }
    return result;
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 50 with ExecutionResult

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

the class OutputCoverageSuiteFitness method getFitness.

/**
 * {@inheritDoc}
 * <p/>
 * Execute all tests and count covered output goals
 */
@Override
public double getFitness(AbstractTestSuiteChromosome<? extends ExecutableChromosome> suite) {
    logger.trace("Calculating test suite fitness");
    double fitness = 0.0;
    List<ExecutionResult> results = runTestSuite(suite);
    boolean hasTimeoutOrTestException = false;
    for (ExecutionResult result : results) {
        if (result.hasTimeout() || result.hasTestException()) {
            hasTimeoutOrTestException = true;
            break;
        }
    }
    Set<TestFitnessFunction> setOfCoveredGoals = new LinkedHashSet<>();
    if (hasTimeoutOrTestException) {
        logger.info("Test suite has timed out, setting fitness to max value " + totalGoals);
        fitness = totalGoals;
    } else
        fitness = computeDistance(results, setOfCoveredGoals);
    int coveredGoals = setOfCoveredGoals.size() + removedGoals.size();
    if (totalGoals > 0)
        suite.setCoverage(this, (double) coveredGoals / (double) totalGoals);
    else
        suite.setCoverage(this, 1.0);
    suite.setNumOfCoveredGoals(this, coveredGoals);
    printStatusMessages(suite, coveredGoals, fitness);
    updateIndividual(this, suite, fitness);
    assert (coveredGoals <= totalGoals) : "Covered " + coveredGoals + " vs total goals " + totalGoals;
    assert (fitness >= 0.0);
    assert (fitness != 0.0 || coveredGoals == totalGoals) : "Fitness: " + fitness + ", " + "coverage: " + coveredGoals + "/" + totalGoals;
    assert (suite.getCoverage(this) <= 1.0) && (suite.getCoverage(this) >= 0.0) : "Wrong coverage value " + suite.getCoverage(this);
    return fitness;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) 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