Search in sources :

Example 36 with InitializationError

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");
    }
}
Also used : Field(java.lang.reflect.Field) InitializationError(org.junit.runners.model.InitializationError) TraversalInterruptionTest(org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest)

Example 37 with InitializationError

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

Example 38 with InitializationError

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();
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) InitializationError(org.junit.runners.model.InitializationError) CaptureLog(org.evosuite.testcarver.capture.CaptureLog) EclipseCompiler(org.eclipse.jdt.internal.compiler.tool.EclipseCompiler) File(java.io.File)

Example 39 with InitializationError

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");
}
Also used : InitializationError(org.junit.runners.model.InitializationError) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 40 with InitializationError

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.
        }
    }
}
Also used : JUnitCore(org.junit.runner.JUnitCore) InitializationError(org.junit.runners.model.InitializationError) Test(org.junit.Test)

Aggregations

InitializationError (org.junit.runners.model.InitializationError)42 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)9 Runner (org.junit.runner.Runner)7 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)5 Field (java.lang.reflect.Field)4 Method (java.lang.reflect.Method)4 JUnitCore (org.junit.runner.JUnitCore)4 RunNotifier (org.junit.runner.notification.RunNotifier)4 File (java.io.File)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 CucumberScenario (cucumber.runtime.model.CucumberScenario)2 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 Test (org.junit.Test)2 AllDefaultPossibilitiesBuilder (org.junit.internal.builders.AllDefaultPossibilitiesBuilder)2 ErrorReportingRunner (org.junit.internal.runners.ErrorReportingRunner)2 ParentRunner (org.junit.runners.ParentRunner)2 FrameworkMethod (org.junit.runners.model.FrameworkMethod)2