use of org.evosuite.runtime.instrumentation.EvoClassLoader in project evosuite by EvoSuite.
the class ClassStateSupportTest method testInitializeClasses.
@Test
public void testInitializeClasses() {
EvoClassLoader loader = new EvoClassLoader();
String className = "com.examples.with.different.packagename.classhandling.TimeA";
// no mocking
RuntimeSettings.deactivateAllMocking();
boolean problem = ClassStateSupport.initializeClasses(loader, className);
Assert.assertFalse(problem);
// with mocking
RuntimeSettings.mockJVMNonDeterminism = true;
className = "com.examples.with.different.packagename.classhandling.TimeB";
problem = ClassStateSupport.initializeClasses(loader, className);
Assert.assertFalse(problem);
}
use of org.evosuite.runtime.instrumentation.EvoClassLoader in project evosuite by EvoSuite.
the class FunctionalMockStatementTest method testConfirmNumberExternal.
private void testConfirmNumberExternal() throws Exception {
assertEquals(IssueWithNumber.RESULT, IssueWithNumber.getResult());
RuntimeInstrumentation.setAvoidInstrumentingShadedClasses(true);
ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
EvoClassLoader loader = new EvoClassLoader();
loader.skipInstrumentation(IssueWithNumber.class.getName());
org.evosuite.runtime.Runtime.getInstance().resetRuntime();
Class<?> klass = loader.loadClass(IssueWithNumber.class.getName());
Method m = klass.getDeclaredMethod("getResult");
String res = (String) m.invoke(null);
assertEquals(IssueWithNumber.RESULT, res);
}
use of org.evosuite.runtime.instrumentation.EvoClassLoader in project evosuite by EvoSuite.
the class ClassResetterTest method testResetOfEnum.
@Test
public void testResetOfEnum() throws Exception {
ClassLoader loader = new EvoClassLoader();
RuntimeSettings.resetStaticState = true;
ClassResetter.getInstance().setClassLoader(loader);
String cut = "com.examples.with.different.packagename.classhandling.FooEnum";
Class<?> klass = loader.loadClass(cut);
Method m = klass.getDeclaredMethod("check");
boolean val = false;
val = (Boolean) m.invoke(null);
Assert.assertTrue(val);
ClassResetter.getInstance().reset(cut);
// make sure that the reset does not create new enum instance values
val = (Boolean) m.invoke(null);
Assert.assertTrue(val);
}
use of org.evosuite.runtime.instrumentation.EvoClassLoader in project evosuite by EvoSuite.
the class EvoRunner method getFromEvoSuiteClassloader.
private static Class<?> getFromEvoSuiteClassloader(Class<?> clazz) throws InitializationError {
try {
/*
* properties like REPLACE_CALLS will be set directly in the JUnit files
*/
// LoggingUtils.loadLogbackForEvoSuite();
/*
* This approach does throw away all the possible instrumentation done on the input clazz,
* eg code coverage of Emma, Cobertura, Javalanche, etc.
* Furthermore, if the classloader used to load EvoRunner is not the same as CUT,
* then loading CUTs will fail (this does happen in "mvn test")
*/
EvoClassLoader classLoader = new EvoClassLoader();
classLoader.skipInstrumentation(clazz.getName());
Thread.currentThread().setContextClassLoader(classLoader);
return Class.forName(clazz.getName(), true, classLoader);
} catch (ClassNotFoundException e) {
throw new InitializationError(e);
}
}
use of org.evosuite.runtime.instrumentation.EvoClassLoader in project evosuite by EvoSuite.
the class MockUrlSystemTest method testLoading_ReadFromURL.
@Test(timeout = 5000)
public void testLoading_ReadFromURL() throws Exception {
// for some reason, this class failed when using loop limit in the search
RuntimeSettings.useVNET = true;
RuntimeSettings.maxNumberOfIterationsPerLoop = 100_000;
MethodCallReplacementCache.resetSingleton();
org.evosuite.runtime.Runtime.getInstance().resetRuntime();
EvoClassLoader loader = new EvoClassLoader();
Class<?> clazz = loader.loadClass(ReadFromURL.class.getCanonicalName());
Method m = clazz.getMethod("checkResource");
boolean b = (Boolean) m.invoke(null);
Assert.assertFalse(b);
EvoSuiteURL evoURL = new EvoSuiteURL("http://www.evosuite.org/index.html");
NetworkHandling.createRemoteTextFile(evoURL, "foo");
b = (Boolean) m.invoke(null);
Assert.assertTrue(b);
}
Aggregations