Search in sources :

Example 6 with InitializationError

use of org.junit.runners.model.InitializationError in project hazelcast by hazelcast.

the class HazelcastParallelClassRunner method getMaxThreads.

private int getMaxThreads(Class<?> clazz) throws InitializationError {
    if (!SPAWN_MULTIPLE_THREADS) {
        return 1;
    }
    ConfigureParallelRunnerWith annotation = clazz.getAnnotation(ConfigureParallelRunnerWith.class);
    if (annotation != null) {
        try {
            Class<? extends ParallelRunnerOptions> optionsClass = annotation.value();
            Constructor constructor = optionsClass.getConstructor();
            ParallelRunnerOptions parallelRunnerOptions = (ParallelRunnerOptions) constructor.newInstance();
            return parallelRunnerOptions.maxParallelTests();
        } catch (Exception e) {
            throw new InitializationError(e);
        }
    } else {
        return DEFAULT_MAX_THREADS;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InitializationError(org.junit.runners.model.InitializationError) ConfigureParallelRunnerWith(com.hazelcast.test.annotation.ConfigureParallelRunnerWith) IOException(java.io.IOException)

Example 7 with InitializationError

use of org.junit.runners.model.InitializationError in project Main by SpartanRefactoring.

the class MetaTester method runChild.

@Override
@SuppressWarnings("unused")
protected void runChild(final FrameworkMethod __, final RunNotifier n) {
    if (hasRan)
        return;
    final Class<?> newTestClass = new ASTTestClassGenerator(testClass).generate(testClass.getSimpleName() + "_Meta", sourceFile);
    final TestSuite suite = new TestSuite(newTestClass);
    suite.run(new TestResult());
    try {
        new BlockJUnit4ClassRunnerWithParametersFactory().createRunnerForTestWithParameters(new TestWithParameters(" ", new TestClass(newTestClass), an.empty.list())).run(n);
    } catch (final InitializationError ignore) {
    /**/
    }
    // Uncomment this to run the original test as well
    /* super.runChild(method, notifier); */
    hasRan = true;
}
Also used : TestWithParameters(org.junit.runners.parameterized.TestWithParameters) TestSuite(junit.framework.TestSuite) InitializationError(org.junit.runners.model.InitializationError) TestResult(junit.framework.TestResult) BlockJUnit4ClassRunnerWithParametersFactory(org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParametersFactory) TestClass(org.junit.runners.model.TestClass)

Example 8 with InitializationError

use of org.junit.runners.model.InitializationError in project jena by apache.

the class ManifestSuite method oneManifest.

private Runner oneManifest(final Manifest manifest, List<Runner> r) {
    // Recurse
    for (Iterator<String> iter = manifest.includedManifests(); iter.hasNext(); ) {
        try {
            r.add(oneManifest(new Manifest(iter.next()), new ArrayList<Runner>()));
        } catch (JenaException ex) {
            r.add(new ErrorReportingRunner(null, ex));
        }
    }
    itemHandler.setTestRunnerList(r);
    manifest.apply(itemHandler);
    try {
        return new Suite((Class<?>) null, r) {

            @Override
            protected String getName() {
                return manifest.getName();
            }
        };
    } catch (InitializationError e) {
        return new ErrorReportingRunner(null, e);
    }
}
Also used : Suite(org.junit.runners.Suite) JenaException(org.apache.jena.shared.JenaException) InitializationError(org.junit.runners.model.InitializationError) ArrayList(java.util.ArrayList) ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner)

Example 9 with InitializationError

use of org.junit.runners.model.InitializationError in project android by JetBrains.

the class GuiTestSuiteRunner method getGuiTestClasses.

@NotNull
private static Class<?>[] getGuiTestClasses(@NotNull Class<?> suiteClass) throws InitializationError {
    List<File> guiTestClassFiles = Lists.newArrayList();
    File parentDir = getParentDir(suiteClass);
    String packagePath = suiteClass.getPackage().getName().replace('.', File.separatorChar);
    int packagePathIndex = parentDir.getPath().indexOf(packagePath);
    assertThat(packagePathIndex).isGreaterThan(-1);
    String testDirPath = parentDir.getPath().substring(0, packagePathIndex);
    findPotentialGuiTestClassFiles(parentDir, guiTestClassFiles);
    List<Class<?>> guiTestClasses = Lists.newArrayList();
    ClassLoader classLoader = suiteClass.getClassLoader();
    for (File classFile : guiTestClassFiles) {
        String path = classFile.getPath();
        String className = path.substring(testDirPath.length(), path.indexOf(DOT_CLASS)).replace(File.separatorChar, '.');
        try {
            Class<?> testClass = classLoader.loadClass(className);
            if (isGuiTest(testClass)) {
                guiTestClasses.add(testClass);
            }
        } catch (ClassNotFoundException e) {
            throw new InitializationError(e);
        }
    }
    return guiTestClasses.toArray(new Class<?>[guiTestClasses.size()]);
}
Also used : InitializationError(org.junit.runners.model.InitializationError) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with InitializationError

use of org.junit.runners.model.InitializationError in project sling by apache.

the class PerformanceRunner method computePerformanceTests.

/**
     * Compute performance tests
     *
     * @return the list containing the performance test methods
     * @throws Exception
     */
protected Collection<? extends FrameworkMethod> computePerformanceTests() throws Exception {
    List<FrameworkMethod> tests = new LinkedList<FrameworkMethod>();
    List<Object> testObjects = new ArrayList<Object>();
    List<Object> testObjectsTmp = new ArrayList<Object>();
    ParameterizedTestList testCenter = new ParameterizedTestList();
    // Retrieve the test objects included in the Performance test suite
    for (FrameworkMethod method : getTestClass().getAnnotatedMethods(PerformanceTestSuite.class)) {
        Object targetObject = getTestClass().getJavaClass().newInstance();
        if (method.getMethod().getReturnType().equals(ParameterizedTestList.class)) {
            testCenter = (ParameterizedTestList) method.getMethod().invoke(targetObject);
            testObjectsTmp = testCenter.getTestObjectList();
            // Iterate through all the test cases and see if they have a factory
            for (Object testObject : testObjectsTmp) {
                Method[] factoryMethods = getSpecificMethods(testObject.getClass(), PerformanceTestFactory.class);
                // If we have a factory method, get all the instance objects returned by this factory
                if (factoryMethods.length > 0) {
                    // Make sure there's only one factory method
                    if (factoryMethods.length > 1) {
                        throw new IllegalStateException("There should be at most one PerformanceTestFactory method");
                    }
                    Method factoryMethod = factoryMethods[0];
                    // Execute the method (statically)
                    Object instances = factoryMethod.invoke(testObject);
                    // If the factory returned an array, make a list
                    if (instances.getClass().isArray()) {
                        instances = Arrays.asList((Object[]) instances);
                    }
                    // If the factory returned a single element, put it in a list
                    if (!(instances instanceof Iterable<?>)) {
                        instances = Collections.singletonList(instances);
                    }
                    testObjects.addAll((List) instances);
                } else {
                    testObjects.add(testObject);
                }
            }
        } else {
            throw new InitializationError("Wrong signature for the @PerformanceTestSuite method");
        }
    }
    // Retrieve the methods before running the methods from the test suite
    List<FrameworkMethod> beforeSuiteMethods = getTestClass().getAnnotatedMethods(BeforeSuite.class);
    if (beforeSuiteMethods.size() > 1) {
        throw new InitializationError("Only one @BeforeSuite method is allowed for a @PerformanceSuite");
    }
    // Retrieve the methods before running the methods from the test suite
    List<FrameworkMethod> afterSuiteMethods = getTestClass().getAnnotatedMethods(AfterSuite.class);
    if (afterSuiteMethods.size() > 1) {
        throw new InitializationError("Only one @AfterSuite method is allowed for a @PerformanceSuite");
    }
    PerformanceSuiteState current = null;
    boolean suiteAlreadyRegistered = false;
    for (PerformanceSuiteState suiteState : suitesState) {
        if (suiteState.testSuiteName.equals(testCenter.getTestSuiteName())) {
            suiteAlreadyRegistered = true;
            suiteState.incrementNumberOfTestMethodsInSuite();
            current = suiteState;
            break;
        }
    }
    // Create a new PerformanceSuiteState object
    PerformanceSuiteState newSuite = new PerformanceSuiteState(testCenter.getTestSuiteName());
    if (!suiteAlreadyRegistered) {
        if (beforeSuiteMethods.size() == 1) {
            newSuite.setBeforeSuiteMethod(beforeSuiteMethods.get(0).getMethod());
        }
        if (afterSuiteMethods.size() == 1) {
            newSuite.setAfterSuiteMethod(afterSuiteMethods.get(0).getMethod());
        }
        current = newSuite;
        newSuite.setTargetObjectSuite(getTestClass().getJavaClass().newInstance());
    }
    // contained in the PerformanceSuite
    if (!testObjects.isEmpty()) {
        for (Object testObject : testObjects) {
            // retrieve the test methods from the test classes
            Method[] testMethods = getSpecificMethods(testObject.getClass(), PerformanceTest.class);
            for (Method method : testMethods) {
                FrameworkPerformanceMethod performaceTestMethod = new FrameworkPerformanceMethod(method, testObject, current, reportLevel, referenceMethod);
                tests.add(performaceTestMethod);
            }
            if (!suiteAlreadyRegistered) {
                newSuite.incrementNumberOfTestMethodsInSuite();
            }
        }
        // add the new suite to the list of suites
        suitesState.add(newSuite);
    }
    // performance test suite
    for (FrameworkMethod method : getTestClass().getAnnotatedMethods(PerformanceTest.class)) {
        Object targetObject = getTestClass().getJavaClass().newInstance();
        FrameworkPerformanceMethod performanceTestMethod = new FrameworkPerformanceMethod(method.getMethod(), targetObject, current, reportLevel, referenceMethod);
        tests.add(performanceTestMethod);
    }
    return tests;
}
Also used : InitializationError(org.junit.runners.model.InitializationError) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) LinkedList(java.util.LinkedList) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Aggregations

InitializationError (org.junit.runners.model.InitializationError)16 ArrayList (java.util.ArrayList)4 Runner (org.junit.runner.Runner)4 IOException (java.io.IOException)3 ErrorReportingRunner (org.junit.internal.runners.ErrorReportingRunner)3 CucumberScenario (cucumber.runtime.model.CucumberScenario)2 Constructor (java.lang.reflect.Constructor)2 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 AllDefaultPossibilitiesBuilder (org.junit.internal.builders.AllDefaultPossibilitiesBuilder)2 JUnitCore (org.junit.runner.JUnitCore)2 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)2 ParentRunner (org.junit.runners.ParentRunner)2 FrameworkMethod (org.junit.runners.model.FrameworkMethod)2 TestClass (org.junit.runners.model.TestClass)2 Pact (au.com.dius.pact.model.Pact)1 PactBroker (au.com.dius.pact.provider.junit.loader.PactBroker)1 PactFolder (au.com.dius.pact.provider.junit.loader.PactFolder)1 PactLoader (au.com.dius.pact.provider.junit.loader.PactLoader)1 PactSource (au.com.dius.pact.provider.junit.loader.PactSource)1