Search in sources :

Example 51 with TestCase

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

the class TestOverloading method testOverloadedConstructor.

@Test
public void testOverloadedConstructor() {
    Class<?> clazz = ClassWithOverloadedMethods.class;
    Constructor<?> constructor1 = clazz.getConstructors()[0];
    Constructor<?> constructor2 = clazz.getConstructors()[1];
    GenericConstructor genericConstructor1 = new GenericConstructor(constructor1, clazz);
    GenericConstructor genericConstructor2 = new GenericConstructor(constructor2, clazz);
    TestCase test = new DefaultTestCase();
    ConstantValue intValue = new ConstantValue(test, int.class);
    VariableReference integerVar = new VariableReferenceImpl(test, Integer.class);
    List<VariableReference> parameters = Arrays.asList(intValue, integerVar);
    assertTrue(genericConstructor1.isOverloaded(parameters));
    assertTrue(genericConstructor2.isOverloaded(parameters));
}
Also used : ClassWithOverloadedMethods(com.examples.with.different.packagename.utils.generic.ClassWithOverloadedMethods) VariableReference(org.evosuite.testcase.variable.VariableReference) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) VariableReferenceImpl(org.evosuite.testcase.variable.VariableReferenceImpl) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) ConstantValue(org.evosuite.testcase.variable.ConstantValue) Test(org.junit.Test)

Example 52 with TestCase

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

the class TestOverloading method testOverloadedMethod.

@Test
public void testOverloadedMethod() {
    Class<?> clazz = ClassWithOverloadedMethods.class;
    Method method1 = clazz.getMethods()[0];
    Method method2 = clazz.getMethods()[1];
    GenericMethod genericMethod1 = new GenericMethod(method1, clazz);
    GenericMethod genericMethod2 = new GenericMethod(method2, clazz);
    TestCase test = new DefaultTestCase();
    ConstantValue intValue = new ConstantValue(test, int.class);
    VariableReference integerVar = new VariableReferenceImpl(test, Integer.class);
    List<VariableReference> parameters1 = Arrays.asList(intValue);
    List<VariableReference> parameters2 = Arrays.asList(integerVar);
    assertTrue(genericMethod1.isOverloaded());
    assertTrue(genericMethod2.isOverloaded());
    assertTrue(genericMethod1.isOverloaded(parameters1));
    assertTrue(genericMethod2.isOverloaded(parameters1));
    assertTrue(genericMethod1.isOverloaded(parameters2));
    assertTrue(genericMethod2.isOverloaded(parameters2));
}
Also used : ClassWithOverloadedMethods(com.examples.with.different.packagename.utils.generic.ClassWithOverloadedMethods) VariableReference(org.evosuite.testcase.variable.VariableReference) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) VariableReferenceImpl(org.evosuite.testcase.variable.VariableReferenceImpl) Method(java.lang.reflect.Method) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) ConstantValue(org.evosuite.testcase.variable.ConstantValue) Test(org.junit.Test)

Example 53 with TestCase

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

the class TestOverloading method testNotOverloadedConstructor.

@Test
public void testNotOverloadedConstructor() {
    Class<?> clazz = ClassWithoutOverloadedMethods.class;
    Constructor<?> constructor1 = clazz.getConstructors()[0];
    Constructor<?> constructor2 = clazz.getConstructors()[1];
    GenericConstructor genericConstructor1 = new GenericConstructor(constructor1, clazz);
    GenericConstructor genericConstructor2 = new GenericConstructor(constructor2, clazz);
    TestCase test = new DefaultTestCase();
    ConstantValue intValue = new ConstantValue(test, int.class);
    VariableReference stringVar = new VariableReferenceImpl(test, String.class);
    List<VariableReference> parameters1 = Arrays.asList(intValue);
    List<VariableReference> parameters2 = Arrays.asList(stringVar);
    assertFalse(genericConstructor1.isOverloaded(parameters1));
    assertFalse(genericConstructor2.isOverloaded(parameters2));
    assertFalse(genericConstructor1.isOverloaded(parameters2));
    assertFalse(genericConstructor2.isOverloaded(parameters1));
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) VariableReferenceImpl(org.evosuite.testcase.variable.VariableReferenceImpl) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) ConstantValue(org.evosuite.testcase.variable.ConstantValue) ClassWithoutOverloadedMethods(com.examples.with.different.packagename.utils.generic.ClassWithoutOverloadedMethods) Test(org.junit.Test)

Example 54 with TestCase

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

the class TestSerialization method testSerializationNonEmptySuite.

@Test
public void testSerializationNonEmptySuite() throws IOException, ClassNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    double fitness = 0.9950513142057124d;
    TestSuiteChromosome chromosome = new TestSuiteChromosome();
    TestChromosome testChromosome = new TestChromosome();
    TestCase test = new DefaultTestCase();
    PrimitiveStatement<?> statement = PrimitiveStatement.getPrimitiveStatement(test, int.class);
    test.addStatement(statement);
    testChromosome.setTestCase(test);
    testChromosome.setFitness(null, 3.14d);
    chromosome.setFitness(null, fitness);
    chromosome.setCoverage(null, 0.5);
    chromosome.updateAge(24);
    chromosome.setChanged(true);
    chromosome.addTest(testChromosome);
    oos.writeObject(chromosome);
    byte[] baSerialized = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(baSerialized);
    ObjectInputStream ois = new ObjectInputStream(bais);
    TestSuiteChromosome copy = (TestSuiteChromosome) ois.readObject();
    Assert.assertEquals(chromosome.getFitness(), copy.getFitness(), 0.0);
    Assert.assertEquals(chromosome.getAge(), copy.getAge());
    Assert.assertEquals(chromosome.getCoverage(), copy.getCoverage(), 0.0);
    Assert.assertEquals(chromosome.getCoveredGoals(), copy.getCoveredGoals());
    Assert.assertEquals(chromosome.isChanged(), copy.isChanged());
    Assert.assertEquals(chromosome.getTestChromosome(0).getFitness(), copy.getTestChromosome(0).getFitness(), 0.0);
}
Also used : DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) ObjectOutputStream(java.io.ObjectOutputStream) TestChromosome(org.evosuite.testcase.TestChromosome) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 55 with TestCase

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

the class FunctionalMockStatementTest method testPackageLevel_differentPackage_instrumentation_public.

/*
     * This test fails when Mockito is instrumented (it would pass if org.mockito. is excluded from instrumentation.
     * However, in the packaged version, Mockito is shaded and thus isn't actually instrumented. I don't have a good
     * solution to fix this test, hence I've marked it as ignored. (Gordon, 9.2.2018)
     */
@Test
public void testPackageLevel_differentPackage_instrumentation_public() throws Exception {
    TestCase tc = new DefaultTestCase();
    RuntimeInstrumentation.setAvoidInstrumentingShadedClasses(true);
    ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
    InstrumentingClassLoader loader = new InstrumentingClassLoader();
    Class<?> example = loader.loadClass("com.examples.with.different.packagename.fm.ExamplePublicLevel");
    VariableReference ref = new VariableReferenceImpl(tc, example);
    FunctionalMockStatement mockStmt = new FunctionalMockStatement(tc, ref, example);
    tc.addStatement(mockStmt);
    execute(tc);
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) VariableReferenceImpl(org.evosuite.testcase.variable.VariableReferenceImpl) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) NonInstrumentingClassLoader(org.evosuite.instrumentation.NonInstrumentingClassLoader) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

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