use of org.junit.runners.model.InitializationError in project janusgraph by JanusGraph.
the class BerkeleyProcessStandardSuite method getTestList.
private static Class<?>[] getTestList() throws InitializationError {
try {
final Field field = ProcessStandardSuite.class.getDeclaredField("allTests");
field.setAccessible(true);
return (Class<?>[]) ArrayUtils.removeElement((Class<?>[]) field.get(null), TraversalInterruptionTest.class);
} catch (ReflectiveOperationException e) {
throw new InitializationError("Unable to create test list");
}
}
use of org.junit.runners.model.InitializationError 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.junit.runners.model.InitializationError in project evosuite by EvoSuite.
the class PostProcessor method process.
/**
* @param logs logs of captured interaction
* @param packages package names associated with logs. Mapping logs.get(i) belongs to packages.get(i)
* @throws IOException
*/
public static void process(final List<CaptureLog> logs, final List<String> packages, final List<Class<?>[]> observedClasses) throws IOException {
if (logs == null) {
throw new NullPointerException("list of CaptureLogs must not be null");
}
if (packages == null) {
throw new NullPointerException("list of package names associated with logs must not be null");
}
if (observedClasses == null) {
throw new NullPointerException("list of classes to be observed must not be null");
}
final int size = logs.size();
if (packages.size() != size || observedClasses.size() != size) {
throw new IllegalArgumentException("given lists must have same size");
}
// create post-processing sources in os specific temp folder
final File tempDir = new File(System.getProperty("java.io.tmpdir"), "postprocessing_" + System.currentTimeMillis());
tempDir.mkdir();
CaptureLog log;
String packageName;
Class<?>[] classes;
String targetFolder;
File targetFile;
final StringBuilder testClassNameBuilder = new StringBuilder();
String testClassName;
for (int i = 0; i < size; i++) {
// =============== prepare carved test for post-processing ================================================
packageName = packages.get(i);
targetFolder = packageName.replace(".", File.separator);
classes = observedClasses.get(i);
if (classes.length == 0) {
throw new IllegalArgumentException("there must be at least one class to be observed");
}
// for(int j = 0; j < classes.length; j++)
// {
// testClassNameBuilder.append(classes[j].getSimpleName());
// if(testClassNameBuilder.length() >= 10)
// {
// break;
// }
// }
testClassNameBuilder.append("CarvedTest");
log = logs.get(i);
long s = System.currentTimeMillis();
logger.debug(">>>> (postprocess) start test create ");
targetFile = new File(tempDir, targetFolder);
targetFile.mkdirs();
testClassName = getFreeClassName(targetFile, testClassNameBuilder.toString());
targetFile = new File(targetFile, testClassName + ".java");
// write out test files containing post-processing statements
writeTest(log, packageName, testClassName, classes, targetFile, true);
logger.debug(">>>> (postprocess) end test creation -> " + (System.currentTimeMillis() - s) / 1000);
// =============== compile generated post-processing test ================================================
final JavaCompiler compiler = new EclipseCompiler();
// final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
final StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(new File[] { targetFile }));
// --- add modified bins (see Transformer and ClassPreparer.createPreparedBin()) to class path
String classPath = Configuration.INSTANCE.getProperty(Configuration.MODIFIED_BIN_LOC);
classPath += File.pathSeparator + System.getProperty("java.class.path");
final Boolean wasCompilationSuccess = compiler.getTask(null, fileManager, null, Arrays.asList(new String[] { "-cp", classPath }), null, compilationUnits).call();
if (!wasCompilationSuccess) {
logger.error("Compilation was not not successful for " + targetFile);
fileManager.close();
continue;
}
fileManager.close();
// =============== execute + observe post-processing test run ================================================
final PostProcessorClassLoader cl = new PostProcessorClassLoader(tempDir);
final Class<?> testClass = cl.findClass(packageName + '.' + testClassName);
BlockJUnit4ClassRunner testRunner;
try {
testRunner = new BlockJUnit4ClassRunner(testClass);
testRunner.run(new RunNotifier());
} catch (InitializationError e) {
logger.error("" + e, e);
}
// ============== generate final test file ================================================================
final String targetDir = Configuration.INSTANCE.getProperty(Configuration.GEN_TESTS_LOC);
targetFile = new File(new File(targetDir), targetFolder);
targetFile.mkdirs();
testClassName = getFreeClassName(targetFile, testClassNameBuilder.toString());
targetFile = new File(targetFile, testClassName + ".java");
writeTest(log, packageName, testClassName, classes, targetFile, false);
// recycle StringBuilder for testClassName
testClassNameBuilder.setLength(0);
}
// clean up post-processing stuff
tempDir.delete();
}
use of org.junit.runners.model.InitializationError in project vertx-auth by vert-x3.
the class MongoAuthNO_SALTTest method initTestUsers.
private void initTestUsers() throws Exception {
log.info("initTestUsers");
List<InternalUser> users = createUserList();
CountDownLatch latch = new CountDownLatch(users.size());
for (InternalUser user : users) {
if (!initOneUser(user, latch))
throw new InitializationError("could not create users");
}
awaitLatch(latch);
if (!verifyUserData())
throw new InitializationError("users weren't created");
}
use of org.junit.runners.model.InitializationError in project randomizedtesting by randomizedtesting.
the class TestCustomMethodProvider method testJUnit4Invalid.
@Test
public void testJUnit4Invalid() {
Class<?>[] invalid = { T2.class, T3.class, T4.class, ST1.class, ST2.class, ST3.class, ST4.class, AT1.class };
for (Class<?> cl : invalid) {
try {
new JUnitCore().run(new RandomizedRunner(cl));
Assert.fail("Expected to fail for: " + cl);
} catch (InitializationError e) {
// expected.
}
}
}
Aggregations