List<Assertion> assertions; Set<Integer> killed = new HashSet<Integer>(); assertions = test.getAssertions(); for (Assertion assertion : assertions) { for (Mutation m : executedMutants) {
protected void filterFailingAssertions(TestCase test) { // Make sure we are not keeping assertions influenced by static state // TODO: Need to handle statically initialized classes ExecutionResult result = runTest(test); Set<Assertion> invalidAssertions = new HashSet<Assertion>(); for(Assertion assertion : test.getAssertions()) { for(OutputTrace<?> outputTrace : result.getTraces()) { if(outputTrace.isDetectedBy(assertion)) { invalidAssertions.add(assertion); break; } } } logger.info("Removing {} nondeterministic assertions", invalidAssertions.size()); for(Assertion assertion : invalidAssertions) { test.removeAssertion(assertion); } }
boolean hadAssertion = false; for (Assertion a : test.getTheTest().getTestCase().getAssertions()) { String aClass = a.getClass().getSimpleName(); List<String> aTypes = uniqueAssertions.get(aClass);
boolean hadAssertion = test.getTheTest().getTestCase().getAssertions().size() > 0;
for(Assertion assertion : testCase.getAssertions()) { for(Mutation m : assertion.getKilledMutations()) { mutationCoverage.add(new MutationInfo(m));
int assertionCount = regressionTest.getTheTest().getTestCase().getAssertions().size(); totalCount += assertionCount; List<Assertion> assertions = regressionTest.getTheTest().getTestCase().getAssertions(); List<String> assertionComments = new ArrayList<>(); for (Assertion assertion : assertions) {
.getAssertions()) { for (OutputTrace<?> outputTrace : resultA.getTraces()) { if (outputTrace.isDetectedBy(assertion)) {
List<Assertion> assertions = test.getAssertions(); logger.info("Got " + assertions.size() + " assertions"); Map<Integer, Set<Integer>> killMap = new HashMap<Integer, Set<Integer>>(); + killedAfter + "/" + s2); logger.info("Assertions in this test: " + test.getAssertions().size());
@Test public void testPrimitiveArray() { EvoSuite evosuite = new EvoSuite(); String targetClass = ArrayPrimitiveWrapper.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.ASSERTION_STRATEGY = AssertionStrategy.ALL; String[] command = new String[] { "-generateSuite", "-class", targetClass }; Object result = evosuite.parseCommandLine(command); GeneticAlgorithm<?> ga = getGAFromResult(result); boolean hasSameAssertion = false; TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual(); for(TestChromosome testChromosome : best.getTestChromosomes()) { for(Assertion assertion : testChromosome.getTestCase().getAssertions()) { if(assertion instanceof SameAssertion) { hasSameAssertion = true; //Assert.assertEquals(true, ((SameAssertion)assertion).value); } } } System.out.println("EvolvedTestSuite:\n" + best); Assert.assertFalse(hasSameAssertion); }
@Test public void testObjectArray() { EvoSuite evosuite = new EvoSuite(); String targetClass = ArrayObjects.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.SEARCH_BUDGET = 100000; Properties.ASSERTION_STRATEGY = AssertionStrategy.ALL; String[] command = new String[] { "-generateSuite", "-class", targetClass }; Object result = evosuite.parseCommandLine(command); GeneticAlgorithm<?> ga = getGAFromResult(result); boolean hasSameAssertion = false; TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual(); for(TestChromosome testChromosome : best.getTestChromosomes()) { for(Assertion assertion : testChromosome.getTestCase().getAssertions()) { if(assertion instanceof SameAssertion) { hasSameAssertion = true; Assert.assertEquals(false, ((SameAssertion)assertion).value); } } } System.out.println("EvolvedTestSuite:\n" + best); Assert.assertTrue(hasSameAssertion); }
@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); }
System.out.println("EvolvedTestSuite:\n" + best); for(TestChromosome testChromosome : best.getTestChromosomes()) { for(Assertion assertion : testChromosome.getTestCase().getAssertions()) { if(assertion instanceof SameAssertion) { hasSameAssertion = true;
for (TestCase test : suite.getTests()) { boolean hasEnumAssertion = false; for(Assertion ass : test.getAssertions()) { if(ass instanceof PrimitiveAssertion) { Assert.assertTrue(((PrimitiveAssertion)ass).getValue().getClass().isEnum());
@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); } } }
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual(); for(TestChromosome testChromosome : best.getTestChromosomes()) { for(Assertion assertion : testChromosome.getTestCase().getAssertions()) { if(assertion instanceof SameAssertion) { hasSameAssertion = true;