Search in sources :

Example 81 with TestCase

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

the class EnumAssertionSystemTest method testAssertionsIncludeEnums.

@Test
public void testAssertionsIncludeEnums() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ExampleReturningEnum.class.getCanonicalName();
    String[] command = new String[] { "-generateSuite", "-class", targetClass, "-Dassertion_strategy=all" };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome suite = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println(suite.toString());
    Assert.assertTrue(suite.size() > 0);
    for (TestCase test : suite.getTests()) {
        boolean hasEnumAssertion = false;
        for (Assertion ass : test.getAssertions()) {
            if (ass instanceof PrimitiveAssertion) {
                Assert.assertTrue(((PrimitiveAssertion) ass).getValue().getClass().isEnum());
                hasEnumAssertion = true;
            }
        }
        Assert.assertTrue("Test has no enum assertions: " + test.toCode(), hasEnumAssertion);
    }
    int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
    Assert.assertEquals("Wrong number of goals: ", 3, goals);
    Assert.assertEquals("Non-optimal coverage: ", 1d, suite.getCoverage(), 0.05);
}
Also used : TestCase(org.evosuite.testcase.TestCase) EvoSuite(org.evosuite.EvoSuite) ExampleNullAssertion(com.examples.with.different.packagename.ExampleNullAssertion) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 82 with TestCase

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

the class EnumAssertionSystemTest method testAssertionsPrefersEnums.

@Test
public void testAssertionsPrefersEnums() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ExampleReturningEnum.class.getCanonicalName();
    String[] command = new String[] { "-generateSuite", "-class", targetClass, "-Dassertion_strategy=mutation" };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome suite = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println(suite.toString());
    Assert.assertTrue(suite.size() > 0);
    for (TestCase test : suite.getTests()) {
        boolean hasEnumAssertion = false;
        for (Assertion ass : test.getAssertions()) {
            if (ass instanceof PrimitiveAssertion) {
                Assert.assertTrue(((PrimitiveAssertion) ass).getValue().getClass().isEnum());
                hasEnumAssertion = true;
            }
        }
        Assert.assertTrue("Test has no enum assertions: " + test.toCode(), hasEnumAssertion);
    }
    int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
    Assert.assertEquals("Wrong number of goals: ", 3, goals);
    Assert.assertEquals("Non-optimal coverage: ", 1d, suite.getCoverage(), 0.05);
}
Also used : TestCase(org.evosuite.testcase.TestCase) EvoSuite(org.evosuite.EvoSuite) ExampleNullAssertion(com.examples.with.different.packagename.ExampleNullAssertion) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 83 with TestCase

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

the class AllAssertionSystemTest method test2.

@Ignore
@Test
public void test2() {
    TestSuiteChromosome suite = generateSuite(ExampleFieldClass.class);
    Assert.assertTrue(suite.size() > 0);
    for (TestCase test : suite.getTests()) {
        Assert.assertTrue("Test has no assertions: " + test.toCode(), test.hasAssertions());
    }
}
Also used : TestCase(org.evosuite.testcase.TestCase) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 84 with TestCase

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

the class AllAssertionSystemTest method test4.

@Ignore
@Test
public void test4() {
    TestSuiteChromosome suite = generateSuite(ExampleStaticVoidSetterClass.class);
    Assert.assertTrue(suite.size() > 0);
    for (TestCase test : suite.getTests()) {
        Assert.assertTrue("Test has no assertions: " + test.toCode(), test.hasAssertions());
    }
}
Also used : TestCase(org.evosuite.testcase.TestCase) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 85 with TestCase

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

the class ContainsAssertionSystemTest method testAssertionsIncludeContains.

@Test
public void testAssertionsIncludeContains() {
    // Properties.INLINE = false;
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ContainerExample.class.getCanonicalName();
    String[] command = new String[] { "-generateSuite", "-class", targetClass, "-Dassertion_strategy=all" };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome suite = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println(suite.toString());
    Assert.assertTrue(suite.size() > 0);
    for (TestCase test : suite.getTests()) {
        boolean hasContainsAssertion = false;
        for (Assertion ass : test.getAssertions()) {
            if (ass instanceof ContainsAssertion) {
                hasContainsAssertion = true;
            }
        }
        Assert.assertTrue("Test has no contains assertions: " + test.toCode(), hasContainsAssertion);
    }
}
Also used : TestCase(org.evosuite.testcase.TestCase) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) 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