/** {@inheritDoc} */ public ExecutionResult runTest(TestCase test) { return TestCaseExecutor.runTest(test); }
private ExecutionResult runTest(TestCase test) { return TestCaseExecutor.runTest(test); }
/** * Some criteria require re-execution with observers. Make sure the results are up-to-date * * @param requiredCriteria * @param origResults * @return */ private List<ExecutionResult> getUpdatedResults(List<Properties.Criterion> requiredCriteria, List<ExecutionResult> origResults) { List<ExecutionObserver> newObservers = new ArrayList<ExecutionObserver>(); if(requiredCriteria.contains(Properties.Criterion.INPUT)) { newObservers.add(new InputObserver()); } if(requiredCriteria.contains(Properties.Criterion.OUTPUT)) { newObservers.add(new OutputObserver()); } if(newObservers.isEmpty()) { return origResults; } for(ExecutionObserver observer : newObservers) TestCaseExecutor.getInstance().addObserver(observer); List<ExecutionResult> newResults = new ArrayList<ExecutionResult>(); for(ExecutionResult result : origResults) { ExecutionResult newResult = TestCaseExecutor.getInstance().runTest(result.test); newResults.add(newResult); } for(ExecutionObserver observer : newObservers) TestCaseExecutor.getInstance().removeObserver(observer); return newResults; }
public void calculateFitness(T c){ ExecutionResult result = TestCaseExecutor.runTest(test); ((TestChromosome) c).setLastExecutionResult(result); c.setChanged(false);
/** * This method executes a given test case (i.e., TestChromosome) * * @param c test case (TestChromosome) to execute */ protected void runTest(T c){ if (!c.isChanged()) return; // run the test TestCase test = ((TestChromosome) c).getTestCase(); ExecutionResult result = TestCaseExecutor.runTest(test); ((TestChromosome) c).setLastExecutionResult(result); c.setChanged(false); // notify the fitness evaluation (i.e., the test is executed) notifyEvaluation(c); }
ExecutionResult executionResult = null; try { executionResult = TestCaseExecutor.runTest(test);
ExecutionResult result = TestCaseExecutor.runTest(test); ((TestChromosome) c).setLastExecutionResult(result); c.setChanged(false);
/** * Run the test against this contract and determine whether it reports a * failure * * @param test * a {@link org.evosuite.testcase.TestCase} object. * @return a boolean. */ public boolean fails(TestCase test) { ContractChecker.setActive(false); TestCaseExecutor executor = TestCaseExecutor.getInstance(); SingleContractChecker checker = new SingleContractChecker(this); executor.addObserver(checker); TestCaseExecutor.runTest(test); executor.removeObserver(checker); //ContractChecker.setActive(true); return !checker.isValid(); }
/** * First execute (if needed) the test cases to be sure to have latest correct data, * and then send it to Master */ public static void executedAndThenSendIndividualToMaster(TestSuiteChromosome testSuite) throws IllegalArgumentException{ if(testSuite == null){ throw new IllegalArgumentException("No defined test suite to send"); } if(!Properties.NEW_STATISTICS) return; /* * TODO: shouldn't a test that was never executed always be executed before sending? * ie, do we really need a separated public sendIndividualToMaster??? */ for (TestChromosome test : testSuite.getTestChromosomes()) { if (test.getLastExecutionResult() == null) { ExecutionResult result = TestCaseExecutor.runTest(test.getTestCase()); test.setLastExecutionResult(result); } } sendCoveredInfo(testSuite); sendExceptionInfo(testSuite); sendIndividualToMaster(testSuite); }
logger.info("Current test: " + i + "/" + Properties.NUM_RANDOM_TESTS); TestChromosome test = factory.getChromosome(); ExecutionResult result = TestCaseExecutor.runTest(test.getTestCase()); Integer pos = result.getFirstPositionOfThrownException(); if (pos != null) {
@Test public void testCharacter() throws SecurityException, NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); ArrayReference characterArray0 = builder.appendArrayStmt(Character[].class, 10); VariableReference character0 = builder.appendNull(Character.class); builder.appendAssignment(characterArray0, 0, character0); builder.appendAssignment(character0, characterArray0, 0); builder.appendMethod(character0, Character.class.getMethod("toString")); DefaultTestCase tc = builder.getDefaultTestCase(); ExecutionResult ret_val = TestCaseExecutor.runTest(tc); assertNotNull(ret_val); assertFalse(ret_val.explicitExceptions.isEmpty()); }
@Test public void testByte() throws SecurityException, NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); ArrayReference integerArray0 = builder.appendArrayStmt(Byte[].class, 10); VariableReference integer0 = builder.appendNull(Byte.class); builder.appendAssignment(integerArray0, 0, integer0); builder.appendAssignment(integer0, integerArray0, 0); builder.appendMethod(integer0, Byte.class.getMethod("toString")); DefaultTestCase tc = builder.getDefaultTestCase(); ExecutionResult ret_val = TestCaseExecutor.runTest(tc); assertNotNull(ret_val); assertFalse(ret_val.explicitExceptions.isEmpty()); }
@Test public void testFloat() throws SecurityException, NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); ArrayReference floatArray0 = builder.appendArrayStmt(Float[].class, 10); VariableReference float0 = builder.appendNull(Float.class); builder.appendAssignment(floatArray0, 0, float0); builder.appendAssignment(float0, floatArray0, 0); builder.appendMethod(float0, Float.class.getMethod("toString")); DefaultTestCase tc = builder.getDefaultTestCase(); System.out.println(tc.toCode()); ExecutionResult ret_val = TestCaseExecutor.runTest(tc); assertNotNull(ret_val); assertFalse(ret_val.explicitExceptions.isEmpty()); }
@Test public void testInteger() throws SecurityException, NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); ArrayReference integerArray0 = builder.appendArrayStmt(Integer[].class, 10); VariableReference integer0 = builder.appendNull(Integer.class); builder.appendAssignment(integerArray0, 0, integer0); builder.appendAssignment(integer0, integerArray0, 0); builder.appendMethod(integer0, Integer.class.getMethod("toString")); DefaultTestCase tc = builder.getDefaultTestCase(); ExecutionResult ret_val = TestCaseExecutor.runTest(tc); assertNotNull(ret_val); assertFalse(ret_val.explicitExceptions.isEmpty()); }
@Test public void testDouble() throws SecurityException, NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); ArrayReference doubleArray0 = builder.appendArrayStmt(Double[].class, 10); VariableReference double0 = builder.appendNull(Double.class); builder.appendAssignment(doubleArray0, 0, double0); builder.appendAssignment(double0, doubleArray0, 0); builder.appendMethod(double0, Double.class.getMethod("floatValue")); DefaultTestCase tc = builder.getDefaultTestCase(); ExecutionResult ret_val = TestCaseExecutor.runTest(tc); assertNotNull(ret_val); assertFalse(ret_val.explicitExceptions.isEmpty()); }
@Test public void testLong() throws SecurityException, NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); ArrayReference longArray0 = builder.appendArrayStmt(Long[].class, 10); VariableReference long0 = builder.appendNull(Long.class); builder.appendAssignment(longArray0, 0, long0); builder.appendAssignment(long0, longArray0, 0); builder.appendMethod(long0, Long.class.getMethod("toString")); DefaultTestCase tc = builder.getDefaultTestCase(); ExecutionResult ret_val = TestCaseExecutor.runTest(tc); assertNotNull(ret_val); assertFalse(ret_val.explicitExceptions.isEmpty()); }
@Test public void testShort() throws SecurityException, NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); ArrayReference integerArray0 = builder.appendArrayStmt(Short[].class, 10); VariableReference integer0 = builder.appendNull(Short.class); builder.appendAssignment(integerArray0, 0, integer0); builder.appendAssignment(integer0, integerArray0, 0); builder.appendMethod(integer0, Short.class.getMethod("toString")); DefaultTestCase tc = builder.getDefaultTestCase(); ExecutionResult ret_val = TestCaseExecutor.runTest(tc); assertNotNull(ret_val); assertFalse(ret_val.explicitExceptions.isEmpty()); } }
test.setLastExecutionResult(TestCaseExecutor.runTest(test.getTestCase())); test.setChanged(false);
@Test public void testRuntimeException() { String targetClass = SourceExceptions.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.REPLACE_CALLS = true; Properties.CRITERION = new Properties.Criterion[]{Properties.Criterion.LINE, Properties.Criterion.EXCEPTION}; EvoSuite evosuite = new EvoSuite(); String[] command = new String[]{"-generateSuite", "-class", targetClass}; Object result = evosuite.parseCommandLine(command); GeneticAlgorithm<?> ga = getGAFromResult(result); TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual(); Assert.assertNotNull(best); TestCaseExecutor.getInstance().initExecutor(); for(TestChromosome test : best.getTestChromosomes()) { ExecutionResult executionResult = TestCaseExecutor.getInstance().runTest(test.getTestCase()); test.setLastExecutionResult(executionResult); } String code = best.toString(); Assert.assertTrue("Code:\n"+code, code.contains("verifyException(\"com.examples.with.different.packagename.mock.java.lang.SourceExceptions\",")); Assert.assertTrue("Code:\n"+code, code.contains("verifyException(\"com.examples.with.different.packagename.mock.java.lang.SourceExceptions$Foo\",")); } }