public List<TestCase> getTests() { List<TestCase> tests = new ArrayList<TestCase>(); for (TestChromosome test : this.tests) { RegressionTestChromosome rtc = (RegressionTestChromosome) test; tests.add(rtc.getTheTest().getTestCase()); } return tests; }
public void removeCoveredGoal(TestFitnessFunction f) { for (TestChromosome test : tests) { test.getTestCase().removeCoveredGoal(f); } }
@Override public void searchFinished(GeneticAlgorithm<?> algorithm) { Chromosome individual = algorithm.getBestIndividual(); if(individual instanceof TestChromosome) { TestChromosome testChromosome = (TestChromosome)individual; testPool.add(testChromosome.getTestCase()); } else if(individual instanceof TestSuiteChromosome) { TestSuiteChromosome testSuiteChromosome = (TestSuiteChromosome) individual; testPool.addAll(testSuiteChromosome.getTests()); } }
@Override public String toString() { String testSuiteString = ""; for (TestChromosome test : tests) { testSuiteString += ((RegressionTestChromosome) test).getTheTest() .getTestCase().toCode(); testSuiteString += "\n"; } return testSuiteString; }
public void filterFailingAssertions(TestSuiteChromosome testSuite) { List<TestChromosome> tests = testSuite.getTestChromosomes(); for(TestChromosome test : tests) { filterFailingAssertions(test.getTestCase()); } // Execute again in different order Randomness.shuffle(tests); for(TestChromosome test : tests) { filterFailingAssertions(test.getTestCase()); } }
private static boolean testStatementCommentNotContains(RegressionTestChromosome test, int statementPos, String compareComment) { return (test.getTheTest().getTestCase().hasStatement(statementPos) && !test.getTheTest().getTestCase().getStatement(statementPos) .getComment().contains(compareComment)); }
private void ensureExecutionResultHasTraces(TestChromosome individual, ExecutionResult result) { if(result.getTraces().isEmpty() && observerClasses.length > 0) { ExecutionResult newResult = runTest(individual.getTestCase()); for(Class<?> observerClass : observerClasses) { OutputTrace<?> trace = newResult.getTrace(observerClass); result.setTrace(trace, observerClass); } } }
/** * */ protected void updateClassloader() { if (theTest.isChanged()) { theSameTestForTheOtherClassLoader = (TestChromosome) theTest.clone(); ((DefaultTestCase) theSameTestForTheOtherClassLoader.getTestCase()) .changeClassLoader(TestGenerationContext.getInstance().getRegressionClassLoaderForSUT()); } }
private void removeUnusedVariables(RegressionTestSuiteChromosome suite) { for (TestChromosome testChromosome : suite.getTestChromosomes()) { RegressionTestChromosome test = (RegressionTestChromosome) testChromosome; boolean changed = TestCaseMinimizer.removeUnusedVariables(test.getTheTest().getTestCase()); if (changed) { test.updateClassloader(); executeSuite(suite); } } }
private ExecutionResult getExecutionResult(TestChromosome individual) { ExecutionResult origResult = individual.getLastExecutionResult(); if(origResult == null||individual.isChanged()) { origResult = runTest(individual.getTestCase()); individual.setLastExecutionResult(origResult); individual.setChanged(false); } return individual.getLastExecutionResult(); }
@Test public void testBeanDateConverterUtils2() { Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.DateConverterTest2.class.getCanonicalName(); Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.DateConverter.class.getCanonicalName(); Properties.SEED_MUTATIONS = 1; Properties.SEED_CLONE = 1; JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory( null); Assert.assertEquals(1, factory.getNumCarvedTestCases()); String code = factory.getChromosome().getTestCase().toCode(); System.out.println(code); }
@Test public void testBeanDateConverterUtils3() { Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.DateConverterTest3.class.getCanonicalName(); Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.DateConverter.class.getCanonicalName(); Properties.SEED_MUTATIONS = 1; Properties.SEED_CLONE = 1; JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory( null); Assert.assertEquals(1, factory.getNumCarvedTestCases()); String code = factory.getChromosome().getTestCase().toCode(); System.out.println(code); }
@Test public void testBeanDateConverterUtils1() { Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.DateConverterTest1.class.getCanonicalName(); Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.DateConverter.class.getCanonicalName(); Properties.SEED_MUTATIONS = 1; Properties.SEED_CLONE = 1; JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory( null); Assert.assertEquals(1, factory.getNumCarvedTestCases()); String code = factory.getChromosome().getTestCase().toCode(); System.out.println(code); }
@Test public void testBeanDateConverterUtils5() { Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.DateConverterTest5.class.getCanonicalName(); Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.DateConverter.class.getCanonicalName(); Properties.SEED_MUTATIONS = 1; Properties.SEED_CLONE = 1; JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory( null); Assert.assertEquals(1, factory.getNumCarvedTestCases()); String code = factory.getChromosome().getTestCase().toCode(); System.out.println(code); }
@Test public void testBeanDateConverterUtils11() { Properties.SELECTED_JUNIT = com.examples.with.different.packagename.testcarver.DateConverterTest11.class.getCanonicalName(); Properties.TARGET_CLASS = com.examples.with.different.packagename.testcarver.DateConverter.class.getCanonicalName(); Properties.SEED_MUTATIONS = 1; Properties.SEED_CLONE = 1; JUnitTestCarvedChromosomeFactory factory = new JUnitTestCarvedChromosomeFactory( null); Assert.assertEquals(1, factory.getNumCarvedTestCases()); String code = factory.getChromosome().getTestCase().toCode(); System.out.println(code); }
protected void restore(TestChromosome test) { if (backup == null) return; test.setTestCase(backup.getTestCase().clone()); test.copyCachedResults(backup); //test.setFitness(backup.getFitness()); test.setFitnessValues(backup.getFitnessValues()); test.setPreviousFitnessValues(backup.getPreviousFitnessValues()); test.setChanged(backup.isChanged()); }
@Test public void testExcludeMethod() throws Exception{ TestChromosome tc = new TestChromosome(); TestFactory factory = TestFactory.getInstance(); //'reset' is a method that shouldn't be used in a test factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("reset"), EvoServletState.class), 0, 0); Assert.assertEquals(tc.getTestCase().toCode(), 1, tc.size()); Assert.assertFalse(ConstraintVerifier.verifyTest(tc)); }
@Test public void testNoDirectInsertion() throws Exception{ TestChromosome tc = new TestChromosome(); TestFactory factory = TestFactory.getInstance(); GenericMethod gm = new GenericMethod(ConstraintVerifierTest.class.getDeclaredMethod("noDirect", null), ConstraintVerifierTest.class); //should not be possible to insert it int pos = ConstraintVerifier.getAValidPositionForInsertion(gm, tc.getTestCase(), 0); Assert.assertTrue(pos < 0); }
@Test public void testBaseTest() throws Exception{ TestChromosome tc = new TestChromosome(); TestFactory factory = TestFactory.getInstance(); factory.addConstructor(tc.getTestCase(), new GenericConstructor(Object.class.getConstructor(), Object.class), 0, 0); Assert.assertEquals(1, tc.size()); Assert.assertTrue(ConstraintVerifier.verifyTest(tc)); }
@Test public void testEvoSuiteClassExclude() throws Exception{ TestChromosome tc = new TestChromosome(); TestFactory factory = TestFactory.getInstance(); //shouldn't be able to instantiate EvoServletConfig directly factory.addConstructor(tc.getTestCase(), new GenericConstructor(EvoServletConfig.class.getConstructor(), EvoServletConfig.class), 0, 0); Assert.assertEquals(1, tc.size()); Assert.assertFalse(ConstraintVerifier.verifyTest(tc)); } }