Search in sources :

Example 6 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder 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 7 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder 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 8 with TestCaseBuilder

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

the class TestDSETestCaseLocalSearch method buildTestCase0.

/**
 * Creates the test case:
 *
 * <code>
 * int int0 = 10;
 * int int1 = 10;
 * int int2 = 10;
 * Foo.bar(int0,int1,int2);
 * </code>
 *
 * @return
 * @throws NoSuchMethodException
 * @throws SecurityException
 * @throws ClassNotFoundException
 */
private static DefaultTestCase buildTestCase0() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference int0 = builder.appendIntPrimitive(10);
    VariableReference int1 = builder.appendIntPrimitive(10);
    VariableReference int2 = builder.appendIntPrimitive(10);
    Class<?> fooClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    Method barMethod = fooClass.getMethod("bar", int.class, int.class, int.class);
    builder.appendMethod(null, barMethod, int0, int1, int2);
    return builder.getDefaultTestCase();
}
Also used : TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) Method(java.lang.reflect.Method)

Example 9 with TestCaseBuilder

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

the class DowncastTest method testUnnecessaryDownCast.

@Test
public void testUnnecessaryDownCast() throws NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor());
    VariableReference int0 = builder.appendIntPrimitive(42);
    VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getANumber", new Class<?>[] { int.class }), int0);
    // This would be set during execution
    num0.setType(Integer.class);
    VariableReference boolean0 = builder.appendMethod(var, DowncastExample.class.getMethod("testMe", new Class<?>[] { Number.class }), num0);
    PrimitiveAssertion assertion = new PrimitiveAssertion();
    assertion.setSource(boolean0);
    assertion.setValue(false);
    DefaultTestCase test = builder.getDefaultTestCase();
    test.getStatement(boolean0.getStPosition()).addAssertion(assertion);
    test.removeDownCasts();
    assertEquals(Number.class, test.getStatement(2).getReturnClass());
}
Also used : DowncastExample(com.examples.with.different.packagename.test.DowncastExample) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) Test(org.junit.Test)

Example 10 with TestCaseBuilder

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

the class DowncastTest method testDownCastNecessaryForInspectorAssertion.

@Test
public void testDownCastNecessaryForInspectorAssertion() throws NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor());
    VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getAbstractFoo"));
    // This would be set during execution
    num0.setType(ConcreteSubclass.class);
    DefaultTestCase test = builder.getDefaultTestCase();
    Inspector inspector = new Inspector(ConcreteSubclass.class, ConcreteSubclass.class.getMethod("getBar"));
    InspectorAssertion assertion = new InspectorAssertion(inspector, test.getStatement(num0.getStPosition()), num0, true);
    test.getStatement(num0.getStPosition()).addAssertion(assertion);
    test.removeDownCasts();
    System.out.println(test);
    assertEquals(ConcreteSubclass.class, test.getStatement(1).getReturnClass());
}
Also used : DowncastExample(com.examples.with.different.packagename.test.DowncastExample) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) ConcreteSubclass(com.examples.with.different.packagename.test.ConcreteSubclass) Test(org.junit.Test)

Aggregations

TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)146 VariableReference (org.evosuite.testcase.variable.VariableReference)143 Method (java.lang.reflect.Method)129 Test (org.junit.Test)16 DowncastExample (com.examples.with.different.packagename.test.DowncastExample)8 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)8 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)7 ArrayReference (org.evosuite.testcase.variable.ArrayReference)7 MIMEType (com.examples.with.different.packagename.concolic.MIMEType)6 ShowMessageDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowMessageDialogExample)6 Field (java.lang.reflect.Field)6 ConcreteSubclass (com.examples.with.different.packagename.test.ConcreteSubclass)4 ShowInternalMessageDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowInternalMessageDialogExample)2 AbstractSuperclass (com.examples.with.different.packagename.test.AbstractSuperclass)2 AssignmentStatement (org.evosuite.testcase.statements.AssignmentStatement)2 FieldReference (org.evosuite.testcase.variable.FieldReference)2 GenericField (org.evosuite.utils.generic.GenericField)2 CBranchExample (com.examples.with.different.packagename.cbranch.CBranchExample)1 ShowConfirmDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowConfirmDialogExample)1 ShowInputDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowInputDialogExample)1