use of org.evosuite.testcase.variable.VariableReference 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();
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class TestSimilarity method testBasicSimilarityDifferentTypes.
@Test
public void testBasicSimilarityDifferentTypes() {
TestCase test1 = new DefaultTestCase();
TestCase test2 = new DefaultTestCase();
PrimitiveStatement<?> aInt = new IntPrimitiveStatement(test1, 42);
test1.addStatement(aInt);
PrimitiveStatement<?> aInt2 = new IntPrimitiveStatement(test1, 42);
test1.addStatement(aInt2);
PrimitiveStatement<?> bInt = new IntPrimitiveStatement(test2, 42);
test2.addStatement(bInt);
Constructor<?> c = Object.class.getConstructors()[0];
ConstructorStatement cs = new ConstructorStatement(test2, new GenericConstructor(c, Object.class), new ArrayList<VariableReference>());
test2.addStatement(cs);
double score = DiversityObserver.getNeedlemanWunschScore(test1, test2);
Assert.assertTrue(score <= 0);
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testAtMostOnce.
@Test
public void testAtMostOnce() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference servlet = factory.addConstructor(tc.getTestCase(), new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("initServlet", Servlet.class), EvoServletState.class), 1, 0);
// 2 different methods that can be used at most once
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getRequest"), EvoServletState.class), 2, 0);
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getResponse"), EvoServletState.class), 3, 0);
Assert.assertEquals(4, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
// add an invalid new call
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getResponse"), EvoServletState.class), 4, 0);
Assert.assertEquals(5, tc.size());
// check should fail
Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testInitializingBoundedVariable_wrong_inputInOtherMethodBeforeInit.
@Test
public void testInitializingBoundedVariable_wrong_inputInOtherMethodBeforeInit() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference servlet = factory.addConstructor(tc.getTestCase(), new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
factory.addMethod(tc.getTestCase(), new GenericMethod(ConstraintVerifierTest.class.getDeclaredMethod("takeServletAsInput", FakeServlet.class), ConstraintVerifierTest.class), 1, 0);
// initializing bounding variable method cannot be called here after the bounded variable has been used as input in some other method
factory.addMethod(tc.getTestCase(), new GenericMethod(Injector.class.getDeclaredMethod("executePostConstruct", Object.class), Injector.class), 2, 0);
Assert.assertEquals(3, tc.size());
Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testExcludeOthers.
@Test
public void testExcludeOthers() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference servlet = factory.addConstructor(tc.getTestCase(), new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("initServlet", Servlet.class), EvoServletState.class), 1, 0);
VariableReference req = factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getRequest"), EvoServletState.class), 2, 0);
factory.addMethodFor(tc.getTestCase(), req, new GenericMethod(EvoHttpServletRequest.class.getDeclaredMethod("asGET"), EvoHttpServletRequest.class), 3);
Assert.assertEquals(tc.getTestCase().toCode(), 4, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
// once it is set as GET, we should not be able to change it to POST
factory.addMethodFor(tc.getTestCase(), req, new GenericMethod(EvoHttpServletRequest.class.getDeclaredMethod("asPOST"), EvoHttpServletRequest.class), 4);
Assert.assertEquals(tc.getTestCase().toCode(), 5, tc.size());
Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
}
Aggregations