Search in sources :

Example 1 with EvoClassLoader

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);
}
Also used : EvoClassLoader(org.evosuite.runtime.instrumentation.EvoClassLoader) Test(org.junit.Test)

Example 2 with EvoClassLoader

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);
}
Also used : IssueWithNumber(com.examples.with.different.packagename.fm.IssueWithNumber) EvoClassLoader(org.evosuite.runtime.instrumentation.EvoClassLoader) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method)

Example 3 with EvoClassLoader

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);
}
Also used : EvoClassLoader(org.evosuite.runtime.instrumentation.EvoClassLoader) EvoClassLoader(org.evosuite.runtime.instrumentation.EvoClassLoader) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 4 with EvoClassLoader

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);
    }
}
Also used : InitializationError(org.junit.runners.model.InitializationError) EvoClassLoader(org.evosuite.runtime.instrumentation.EvoClassLoader)

Example 5 with EvoClassLoader

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);
}
Also used : ReadFromURL(com.examples.with.different.packagename.mock.java.net.ReadFromURL) EvoSuiteURL(org.evosuite.runtime.testdata.EvoSuiteURL) EvoClassLoader(org.evosuite.runtime.instrumentation.EvoClassLoader) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

EvoClassLoader (org.evosuite.runtime.instrumentation.EvoClassLoader)6 Method (java.lang.reflect.Method)4 Test (org.junit.Test)4 InfiniteWhile (com.examples.with.different.packagename.InfiniteWhile)1 IssueWithNumber (com.examples.with.different.packagename.fm.IssueWithNumber)1 ReadFromURL (com.examples.with.different.packagename.mock.java.net.ReadFromURL)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 TooManyResourcesException (org.evosuite.runtime.TooManyResourcesException)1 EvoSuiteURL (org.evosuite.runtime.testdata.EvoSuiteURL)1 GenericMethod (org.evosuite.utils.generic.GenericMethod)1 InitializationError (org.junit.runners.model.InitializationError)1