Search in sources :

Example 1 with InitializationError

use of org.junit.runners.model.InitializationError in project cucumber-jvm by cucumber.

the class ExamplesRunner method buildRunners.

private static List<Runner> buildRunners(Runtime runtime, CucumberExamples cucumberExamples, JUnitReporter jUnitReporter) {
    List<Runner> runners = new ArrayList<Runner>();
    List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
    for (CucumberScenario scenario : exampleScenarios) {
        try {
            ExecutionUnitRunner exampleScenarioRunner = new ExecutionUnitRunner(runtime, scenario, jUnitReporter);
            runners.add(exampleScenarioRunner);
        } catch (InitializationError initializationError) {
            initializationError.printStackTrace();
        }
    }
    return runners;
}
Also used : Runner(org.junit.runner.Runner) InitializationError(org.junit.runners.model.InitializationError) ArrayList(java.util.ArrayList) CucumberScenario(cucumber.runtime.model.CucumberScenario)

Example 2 with InitializationError

use of org.junit.runners.model.InitializationError in project cucumber-jvm by cucumber.

the class FeatureRunner method buildFeatureElementRunners.

private void buildFeatureElementRunners() {
    for (CucumberTagStatement cucumberTagStatement : cucumberFeature.getFeatureElements()) {
        try {
            ParentRunner featureElementRunner;
            if (cucumberTagStatement instanceof CucumberScenario) {
                featureElementRunner = new ExecutionUnitRunner(runtime, (CucumberScenario) cucumberTagStatement, jUnitReporter);
            } else {
                featureElementRunner = new ScenarioOutlineRunner(runtime, (CucumberScenarioOutline) cucumberTagStatement, jUnitReporter);
            }
            children.add(featureElementRunner);
        } catch (InitializationError e) {
            throw new CucumberException("Failed to create scenario runner", e);
        }
    }
}
Also used : CucumberScenarioOutline(cucumber.runtime.model.CucumberScenarioOutline) InitializationError(org.junit.runners.model.InitializationError) CucumberScenario(cucumber.runtime.model.CucumberScenario) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement) CucumberException(cucumber.runtime.CucumberException) ParentRunner(org.junit.runners.ParentRunner)

Example 3 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 4 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 5 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)

Aggregations

InitializationError (org.junit.runners.model.InitializationError)39 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)9 Runner (org.junit.runner.Runner)7 Method (java.lang.reflect.Method)4 RunNotifier (org.junit.runner.notification.RunNotifier)4 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)4 File (java.io.File)3 Field (java.lang.reflect.Field)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 Map (java.util.Map)2 AllDefaultPossibilitiesBuilder (org.junit.internal.builders.AllDefaultPossibilitiesBuilder)2 ErrorReportingRunner (org.junit.internal.runners.ErrorReportingRunner)2 JUnitCore (org.junit.runner.JUnitCore)2 ParentRunner (org.junit.runners.ParentRunner)2 FrameworkMethod (org.junit.runners.model.FrameworkMethod)2