Search in sources :

Example 11 with InitializationError

use of org.junit.runners.model.InitializationError in project xtext-core by eclipse.

the class RunnerBuilder method getScenarios.

private static Scenario[] getScenarios(Class<?> klass, boolean completeInput) throws InitializationError {
    Scenarios annotation = klass.getAnnotation(Scenarios.class);
    if (annotation == null) {
        return Scenario.values();
    } else if (completeInput) {
        throw new InitializationError("Must not use ProcessedBy.processCompleteInput together with the Scenarios annotation");
    }
    Scenario[] result = annotation.value();
    if (result.length == 0) {
        throw new InitializationError("Must at least specify one smoke test scenario or omit the Scenarios annotation");
    }
    return result;
}
Also used : InitializationError(org.junit.runners.model.InitializationError) Scenarios(org.eclipse.xtext.testing.smoketest.Scenarios) Scenario(org.eclipse.xtext.testing.smoketest.Scenario)

Example 12 with InitializationError

use of org.junit.runners.model.InitializationError in project junit4 by junit-team.

the class Request method classes.

/**
     * Create a <code>Request</code> that, when processed, will run all the tests
     * in a set of classes.
     *
     * @param computer Helps construct Runners from classes
     * @param classes the classes containing the tests
     * @return a <code>Request</code> that will cause all tests in the classes to be run
     */
public static Request classes(Computer computer, Class<?>... classes) {
    try {
        AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder();
        Runner suite = computer.getSuite(builder, classes);
        return runner(suite);
    } catch (InitializationError e) {
        return runner(new ErrorReportingRunner(e, classes));
    }
}
Also used : ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner) AllDefaultPossibilitiesBuilder(org.junit.internal.builders.AllDefaultPossibilitiesBuilder) InitializationError(org.junit.runners.model.InitializationError) ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner)

Example 13 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)

Example 14 with InitializationError

use of org.junit.runners.model.InitializationError in project intellij-community by JetBrains.

the class AllTestsSuite method getSuiteClasses.

private static Class<?>[] getSuiteClasses(Class<?> klass) throws InitializationError {
    TestPackage annotation = klass.getAnnotation(TestPackage.class);
    if (annotation == null)
        throw new InitializationError("No test package specified");
    String testPackage = annotation.value();
    SlowPolicy policy = annotation.policy();
    TestCaseLoader loader = new TestCaseLoader("", true);
    try {
        TestAll.fillTestCases(loader, testPackage, TestAll.getClassRoots());
    } catch (IOException e) {
        throw new InitializationError(e);
    }
    List<Class<?>> result = ContainerUtil.newArrayList();
    for (Class aClass : loader.getClasses()) {
        if (policy == SlowPolicy.ALL) {
            result.add(aClass);
        } else {
            boolean slow = isSlow(aClass);
            if (slow && policy == SlowPolicy.SLOW_ONLY || !slow && policy == SlowPolicy.FAST_ONLY) {
                result.add(aClass);
            }
        }
    }
    return result.toArray(ArrayUtil.EMPTY_CLASS_ARRAY);
}
Also used : InitializationError(org.junit.runners.model.InitializationError) TestCaseLoader(com.intellij.TestCaseLoader) IOException(java.io.IOException)

Example 15 with InitializationError

use of org.junit.runners.model.InitializationError in project intellij-community by JetBrains.

the class JUnit46ClassesRequestBuilder method getClassesRequest.

public static Request getClassesRequest(final String suiteName, Class[] classes, Map classMethods, Class category) {
    boolean canUseSuiteMethod = canUseSuiteMethod(classMethods);
    try {
        if (category != null) {
            try {
                Class.forName("org.junit.experimental.categories.Categories");
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("Categories are not available");
            }
        }
        Runner suite;
        if (canUseSuiteMethod) {
            try {
                Class.forName("org.junit.experimental.categories.Categories");
                suite = new IdeaSuite48(collectWrappedRunners(classes), suiteName, category);
            } catch (ClassNotFoundException e) {
                suite = new IdeaSuite(collectWrappedRunners(classes), suiteName);
            }
        } else {
            final AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder(canUseSuiteMethod);
            try {
                Class.forName("org.junit.experimental.categories.Categories");
                suite = new IdeaSuite48(builder, classes, suiteName, category);
            } catch (ClassNotFoundException e) {
                suite = new IdeaSuite(builder, classes, suiteName);
            }
        }
        return Request.runner(suite);
    } catch (InitializationError e) {
        throw new RuntimeException(e);
    }
}
Also used : ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner) Runner(org.junit.runner.Runner) AllDefaultPossibilitiesBuilder(org.junit.internal.builders.AllDefaultPossibilitiesBuilder) InitializationError(org.junit.runners.model.InitializationError)

Aggregations

InitializationError (org.junit.runners.model.InitializationError)19 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 Field (java.lang.reflect.Field)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