public EnvironmentTestClusterAugmenter(TestCluster cluster) { this.cluster = cluster; testClusterGenerator = TestGenerationContext.getInstance().getTestClusterGenerator(); // testClusterGenerator = new TestClusterGenerator(cluster.getInheritanceTree()); this.handledClasses = new LinkedHashSet<>(); }
private static void loadCallTreeClasses(CallGraph callGraph) { for (String className : callGraph.getClasses()) { if (className.startsWith(Properties.TARGET_CLASS + "$")) { try { Class.forName(className, true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } catch (ClassNotFoundException e) { logger.debug("Error loading " + className + ": " + e); } } } }
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); int branchId = ois.readInt(); if (branchId >= 0) this.branch = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId); else this.branch = null; }
/** * Resets the classes in the list using the Class Loader from the current * Test Generation context * * @param classesToReset */ public void resetClasses(List<String> classesToReset) { ClassLoader loader = TestGenerationContext.getInstance().getClassLoaderForSUT(); resetClasses(classesToReset, loader); }
private ClassNode loadClassNode(String className) throws IOException { ClassReader reader = new ClassReader(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className)); ClassNode cn = new ClassNode(); reader.accept(cn, ClassReader.SKIP_FRAMES); // | ClassReader.SKIP_DEBUG); return cn; }
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); branchFitnesses = new ArrayList<BranchCoverageTestFitness>(); if(GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getActualCFG(className, methodName) != null) { // TODO: Figure out why the CFG may not exist setupDependencies(); } }
private static void analyzeClassName(InheritanceTree inheritanceTree, String className) { InputStream stream = ResourceList.getInstance( TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className); if(stream==null){ throw new IllegalArgumentException("Failed to locate/load class: "+className); } logger.debug("Going to analyze: {}", className); analyzeClassStream(inheritanceTree, stream, false); }
private static boolean findTargetClass(String target) { if (ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).hasClass(target)) { return true; } LoggingUtils.getEvoLogger().info("* Unknown class: " + target + ". Be sure its full qualifying name is correct and the classpath is properly set with '-projectCP'"); return false; }
public void addCastClass(String className, int depth) { try { Class<?> clazz = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(className); GenericClass castClazz = new GenericClass(clazz); addCastClass(castClazz.getWithWildcardTypes(), depth); } catch (ClassNotFoundException e) { // Ignore logger.debug("Error including cast class " + className + " because: " + e); } }
@Before public void setUp() { Properties.CRITERION = new Properties.Criterion[] { Criterion.BRANCH }; Properties.TARGET_CLASS = ShowConfirmDialogExample.class.getCanonicalName(); Properties.REPLACE_GUI = true; RuntimeSettings.mockGUI = true; TestGenerationContext.getInstance().resetContext(); }
@Before public void setUp() { Properties.CRITERION = new Properties.Criterion[] { Criterion.BRANCH }; Properties.TARGET_CLASS = ShowMessageDialogExample.class.getCanonicalName(); Properties.REPLACE_GUI = true; RuntimeSettings.mockGUI = true; TestGenerationContext.getInstance().resetContext(); }
private void initCache() { cache = new Cache(); String cp = ClassPathHandler.getInstance().getTargetProjectClasspath(); // If running in regression mode and current ClassLoader is the regression ClassLoader if(Properties.isRegression() && classLoader==TestGenerationContext.getInstance().getRegressionClassLoaderForSUT()) cp = org.evosuite.Properties.REGRESSIONCP; for(String entry : cp.split(File.pathSeparator)){ addEntry(entry); } }
@Before public void setUp() { Properties.CRITERION = new Properties.Criterion[] { Criterion.BRANCH }; Properties.TARGET_CLASS = ShowInputDialogExample.class.getCanonicalName(); Properties.REPLACE_GUI = true; RuntimeSettings.mockGUI = true; TestGenerationContext.getInstance().resetContext(); }
@Before public void setUp() { Properties.CRITERION = new Properties.Criterion[] { Criterion.BRANCH }; Properties.TARGET_CLASS = TARGET_CLASS; Properties.REPLACE_GUI = true; RuntimeSettings.mockGUI = true; TestGenerationContext.getInstance().resetContext(); }
@After public void tearDown() { RuntimeSettings.mockGUI = DEFAULT_MOCK_GUI; Properties.REPLACE_GUI = DEFAULT_REPLACE_GUI; TestGenerationContext.getInstance().resetContext(); }
private DefaultTestCase createTestCase5() throws NoSuchFieldException, SecurityException, NoSuchMethodException, ClassNotFoundException { final Class<?> mimeTypeClass = TestGenerationContext.getInstance().getClassLoaderForSUT() .loadClass(MIMEType.class.getName()); final Field memField = mimeTypeClass.getDeclaredField("MEM"); final Method toString = mimeTypeClass.getMethod("toString"); final TestCaseBuilder builder = new TestCaseBuilder(); VariableReference mIMEType0 = builder.appendStaticFieldStmt(memField); VariableReference string0 = builder.appendMethod(mIMEType0, toString); System.out.println("Test Case #5=" + builder.toCode()); return builder.getDefaultTestCase(); }
@Test public void testStreamFromFolder() throws Exception{ File localFolder = new File("local_test_data"+File.separator+"aCpEntry"); Assert.assertTrue("ERROR: file "+localFolder+" should be available on local file system",localFolder.exists()); ClassPathHandler.getInstance().addElementToTargetProjectClassPath(localFolder.getAbsolutePath()); String className = "foo.ExternalClass"; InputStream stream = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className); Assert.assertNotNull(stream); stream.close(); }
@Test public void testStreamFromJar() throws Exception{ File localJar = new File("local_test_data"+File.separator+"water-simulator.jar"); Assert.assertTrue("ERROR: file "+localJar+" should be avaialable on local file system",localJar.exists()); ClassPathHandler.getInstance().addElementToTargetProjectClassPath(localJar.getAbsolutePath()); String className = "simulator.DAWN"; InputStream stream = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className); Assert.assertNotNull(stream); stream.close(); }
@Test public void testHasClass(){ Assert.assertTrue(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).hasClass(Foo.class.getName())); Assert.assertTrue(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).hasClass(SubPackageFoo.class.getName())); }
@After public void tearDown() { if (DEFAULT_IS_TRACE_ENABLED) { ExecutionTracer.enableTraceCalls(); } else { ExecutionTracer.disableTraceCalls(); } TestGenerationContext.getInstance().resetContext(); ClassReInitializer.resetSingleton(); System.setProperties(currentProperties); Properties.getInstance().resetToDefaults(); }