@Override public void zero() { this.value = Properties.getTargetClassAndDontInitialise(); }
public ClassPrimitiveStatement(TestCase tc) { // super(tc, new GenericClass(Class.class).getWithWildcardTypes(), super( tc, new GenericClass(Class.class).getWithParameterTypes(new Type[] { Properties.getTargetClassAndDontInitialise() }), Properties.getTargetClassAndDontInitialise()); // super(tc, new GenericClass(Properties.getTargetClass()), // Properties.getTargetClass()); }
protected Collection<VariableReference> getAllVariables(Scope scope) { final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); return scope.getElements(targetClass); }
/** * <p> * getAllObjects * </p> * * @param scope * a {@link org.evosuite.testcase.execution.Scope} object. * @return a {@link java.util.Collection} object. */ protected Collection<Object> getAllObjects(Scope scope) { // TODO: Assignable classes and subclasses? final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); return scope.getObjects(targetClass); }
protected Collection<Pair<VariableReference>> getAllVariablePairs(Scope scope) { Set<Pair<VariableReference>> pairs = new HashSet<Pair<VariableReference>>(); final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); List<VariableReference> objects = scope.getElements(targetClass); for (int i = 0; i < objects.size(); i++) { for (int j = i; j < objects.size(); j++) { pairs.add(new Pair<VariableReference>(objects.get(i), objects.get(j))); } } // for (VariableReference o1 : scope.getElements(Properties.getTargetClass())) { // for (VariableReference o2 : scope.getElements(o1.getVariableClass())) { // pairs.add(new Pair<VariableReference>(o1, o2)); // } // } return pairs; }
/** {@inheritDoc} */ @Override public List<MethodNoExceptionCoverageTestFitness> getCoverageGoals() { List<MethodNoExceptionCoverageTestFitness> goals = new ArrayList<MethodNoExceptionCoverageTestFitness>(); long start = System.currentTimeMillis(); String className = Properties.TARGET_CLASS; Class<?> clazz = Properties.getTargetClassAndDontInitialise(); if (clazz != null) { goals.addAll(getCoverageGoals(clazz, className)); Class<?>[] innerClasses = clazz.getDeclaredClasses(); for (Class<?> innerClass : innerClasses) { String innerClassName = innerClass.getCanonicalName(); goals.addAll(getCoverageGoals(innerClass, innerClassName)); } } goalComputationTime = System.currentTimeMillis() - start; return goals; }
/** {@inheritDoc} */ @Override public List<MethodCoverageTestFitness> getCoverageGoals() { List<MethodCoverageTestFitness> goals = new ArrayList<MethodCoverageTestFitness>(); long start = System.currentTimeMillis(); String className = Properties.TARGET_CLASS; Class<?> clazz = Properties.getTargetClassAndDontInitialise(); if (clazz != null) { goals.addAll(getCoverageGoals(clazz, className)); Class<?>[] innerClasses = clazz.getDeclaredClasses(); for (Class<?> innerClass : innerClasses) { String innerClassName = innerClass.getCanonicalName(); goals.addAll(getCoverageGoals(innerClass, innerClassName)); } } goalComputationTime = System.currentTimeMillis() - start; return goals; }
/** * <p> * getAllObjectPairs * </p> * * @param scope * a {@link org.evosuite.testcase.execution.Scope} object. * @return a {@link java.util.Collection} object. */ protected Collection<Pair<Object>> getAllObjectPairs(Scope scope) { Set<Pair<Object>> pairs = new HashSet<Pair<Object>>(); Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); for (Object o1 : scope.getObjects(targetClass)) { for (Object o2 : scope.getObjects(o1.getClass())) { pairs.add(new Pair<Object>(o1, o2)); } } return pairs; }
private List<Class<?>> getObservedClasses(final CaptureLog log) { List<Class<?>> targetClasses = new ArrayList<Class<?>>(); final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); targetClasses.add(targetClass); String prop = Properties.SELECTED_JUNIT;
private void handleSpecialCases() { if (Properties.P_REFLECTION_ON_PRIVATE > 0 && Properties.REFLECTION_START_PERCENT < 1) { // Check if we should add // PrivateAccess.callDefaultConstructorOfTheClassUnderTest() Class<?> target = Properties.getTargetClassAndDontInitialise(); Constructor<?> constructor = null; try { constructor = target.getDeclaredConstructor(); } catch (NoSuchMethodException e) { } if (constructor != null && Modifier.isPrivate(constructor.getModifiers()) && target.getDeclaredConstructors().length == 1 // Not enums && !target.isEnum()) { Method m = null; try { m = PrivateAccess.class.getDeclaredMethod("callDefaultConstructorOfTheClassUnderTest"); } catch (NoSuchMethodException e) { logger.error("Missing method: " + e.toString()); return; } GenericMethod gm = new GenericMethod(m, PrivateAccess.class); // It is not really an environment method, but not sure how else // to handle it... TestCluster.getInstance().addEnvironmentTestCall(gm); } } }
/** * Check if this statement is related to the unit under test * * @param statement * a {@link org.evosuite.testcase.statements.Statement} object. * @return a boolean. */ protected boolean isTargetStatement(Statement statement) { //if (statement.getReturnClass().equals(Properties.getTargetClass())) // return true; if (statement instanceof MethodStatement) { MethodStatement ms = (MethodStatement) statement; final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (targetClass.equals(ms.getMethod().getDeclaringClass())) return true; } else if (statement instanceof ConstructorStatement) { ConstructorStatement cs = (ConstructorStatement) statement; final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (targetClass.equals(cs.getConstructor().getDeclaringClass())) return true; } else if (statement instanceof FieldStatement) { FieldStatement fs = (FieldStatement) statement; final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (targetClass.equals(fs.getField().getDeclaringClass())) return true; } return false; }
public static boolean isSutException(ExecutionResult result, int exceptionPosition){ if (result.test.getStatement(exceptionPosition) instanceof MethodStatement) { MethodStatement ms = (MethodStatement) result.test.getStatement(exceptionPosition); Method method = ms.getMethod().getMethod(); Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (method.getDeclaringClass().equals(targetClass)){ return true; } } else if (result.test.getStatement(exceptionPosition) instanceof ConstructorStatement) { ConstructorStatement cs = (ConstructorStatement) result.test.getStatement(exceptionPosition); Constructor<?> constructor = cs.getConstructor().getConstructor(); Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (constructor.getDeclaringClass().equals(targetClass)){ return true; } } return false; }
/** * Applies the DSE test generation using the initial population as the initial test cases */ @Override public void generateSolution() { this.notifySearchStarted(); this.initializePopulation(); final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); List<Method> targetStaticMethods = getTargetStaticMethods(targetClass); Collections.sort(targetStaticMethods, new MethodComparator()); logger.debug("Found " + targetStaticMethods.size() + " as entry points for DSE"); for (Method entryMethod : targetStaticMethods) { if (this.isFinished()) { logger.debug("A stoping condition was met. No more tests can be generated using DSE."); break; } if (getBestIndividual().getFitness() == 0) { logger.debug("Best individual reached zero fitness"); break; } logger.debug("Generating tests for entry method" + entryMethod.getName()); int testCaseCount = getBestIndividual().getTests().size(); generateTestCasesAndAppendToBestIndividual(entryMethod); int numOfGeneratedTestCases = getBestIndividual().getTests().size() - testCaseCount; logger.debug(numOfGeneratedTestCases + " tests were generated for entry method " + entryMethod.getName()); } this.updateFitnessFunctionsAndValues(); this.notifySearchFinished(); }
public static boolean canBeFunctionalMocked(Type type) { Class<?> rawClass = new GenericClass(type).getRawClass(); final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (Properties.hasTargetClassBeenLoaded() && GenericClass.isAssignable(targetClass, rawClass)) { return false; } return canBeFunctionalMockedIncludingSUT(type); }
private void readTestCases() throws IllegalStateException { CarvingManager manager = CarvingManager.getInstance(); final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); List<TestCase> tests = manager.getTestsForClass(targetClass); junitTests.addAll(tests); if (junitTests.size() > 0) { totalNumberOfTestsCarved = junitTests.size(); LoggingUtils.getEvoLogger().info("* Using {} carved tests from existing JUnit tests for seeding", junitTests.size()); if (logger.isDebugEnabled()) { for (TestCase test : junitTests) { logger.debug("Carved Test: {}", test.toCode()); } } TestSuiteChromosome suite = new TestSuiteChromosome(); for (TestCase test : junitTests) { suite.addTest(test); } for (Properties.Criterion pc : Properties.CRITERION) { TestSuiteFitnessFunction f = FitnessFunctions.getFitnessFunction(pc); f.getFitness(suite); } carvedCoverage = suite.getCoverage(); } ClientNodeLocal client = ClientServices.getInstance().getClientNode(); client.trackOutputVariable(RuntimeVariable.CarvedTests, totalNumberOfTestsCarved); client.trackOutputVariable(RuntimeVariable.CarvedCoverage,carvedCoverage); }
/** * Execute all tests in a JUnit test suite and add resulting sequences from * carver * * @param targetClass * @param testSuite */ public static ObjectPool getPoolFromJUnit(GenericClass targetClass, Class<?> testSuite) { final JUnitCore runner = new JUnitCore(); final CarvingRunListener listener = new CarvingRunListener(); runner.addListener(listener); final org.evosuite.testcarver.extraction.CarvingClassLoader classLoader = new org.evosuite.testcarver.extraction.CarvingClassLoader(); try { // instrument target class classLoader.loadClass(Properties.TARGET_CLASS); } catch (final ClassNotFoundException e) { throw new RuntimeException(e); } ObjectPool pool = new ObjectPool(); //final Result result = runner.run(testSuite); for (TestCase test : listener.getTestCases().get(Properties.getTargetClassAndDontInitialise())) { // TODO: Maybe we would get the targetClass from the last object generated in the sequence? pool.addSequence(targetClass, test); } // TODO: Some messages based on result return pool; }
continue; final Class<?> targetClass = Properties.getTargetClassAndDontInitialise();
Properties.getTargetClassAndDontInitialise(); if (!Properties.hasTargetClassBeenLoaded()) { logger.warn("Could not initialize SUT before Assertion generation" );
/** * Convert a test suite to a pool * * @param testSuite */ public static ObjectPool getPoolFromTestSuite(TestSuiteChromosome testSuite) { ObjectPool pool = new ObjectPool(); for (TestChromosome testChromosome : testSuite.getTestChromosomes()) { TestCase test = testChromosome.getTestCase().clone(); test.removeAssertions(); /* if (testChromosome.hasException()) { // No code including or after an exception should be in the pool Integer pos = testChromosome.getLastExecutionResult().getFirstPositionOfThrownException(); if (pos != null) { test.chop(pos); } else { test.chop(test.size() - 1); } } */ Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (!testChromosome.hasException() && test.hasObject(targetClass, test.size())) { pool.addSequence(new GenericClass(targetClass), test); } } return pool; }
Properties.getTargetClassAndDontInitialise(); TestCase test = new DefaultTestCase(); VariableReference instance = test.addStatement(new ConstructorStatement(test, new GenericConstructor(DependencyClassWithException.class.getConstructors()[0], DependencyClassWithException.class),