use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestClassInitialization method buildLoadTargetClassTestCase.
private static DefaultTestCase buildLoadTargetClassTestCase(String className) throws EvosuiteError {
DefaultTestCase test = new DefaultTestCase();
StringPrimitiveStatement stmt0 = new StringPrimitiveStatement(test, className);
VariableReference string0 = test.addStatement(stmt0);
try {
Method currentThreadMethod = Thread.class.getMethod("currentThread");
Statement currentThreadStmt = new MethodStatement(test, new GenericMethod(currentThreadMethod, currentThreadMethod.getDeclaringClass()), null, Collections.emptyList());
VariableReference currentThreadVar = test.addStatement(currentThreadStmt);
Method getContextClassLoaderMethod = Thread.class.getMethod("getContextClassLoader");
Statement getContextClassLoaderStmt = new MethodStatement(test, new GenericMethod(getContextClassLoaderMethod, getContextClassLoaderMethod.getDeclaringClass()), currentThreadVar, Collections.emptyList());
VariableReference contextClassLoaderVar = test.addStatement(getContextClassLoaderStmt);
Method loadClassMethod = ClassLoader.class.getMethod("loadClass", String.class);
Statement loadClassStmt = new MethodStatement(test, new GenericMethod(loadClassMethod, loadClassMethod.getDeclaringClass()), contextClassLoaderVar, Collections.singletonList(string0));
test.addStatement(loadClassStmt);
return test;
} catch (NoSuchMethodException | SecurityException e) {
throw new EvosuiteError("Unexpected exception while creating Class Initializer Test Case");
}
}
use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestClassInitialization method checksClassIsLoadedUsingInstrumentingClassLoader.
@Test
public void checksClassIsLoadedUsingInstrumentingClassLoader() throws ClassNotFoundException {
Properties.CLIENT_ON_THREAD = true;
final String className = SimpleClass.class.getCanonicalName();
TestCaseExecutor.initExecutor();
TestGenerationContext.getInstance().resetContext();
ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
InstrumentingClassLoader classLoader = TestGenerationContext.getInstance().getClassLoaderForSUT();
assertFalse(classLoader.getLoadedClasses().contains(className));
DefaultTestCase test = buildLoadTargetClassTestCase(className);
TestCaseExecutor.getInstance().execute(test, Integer.MAX_VALUE);
assertTrue(classLoader.getLoadedClasses().contains(className));
}
use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestDefaultValue method testLong.
@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());
}
use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestDefaultValue method testFloat.
@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());
}
use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestDefaultValue method testCharacter.
@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());
}
Aggregations