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);
}
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);
}
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());
}
}
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());
}
}
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);
}
}
Aggregations