Search in sources :

Example 31 with InitializationError

use of org.junit.runners.model.InitializationError in project st-js by st-js.

the class JUnitSession method init.

/**
 * Starts all the browser and server sessions. If the sessions are already started, this method has no effect.
 *
 * @throws InitializationError
 */
private void init(Class<?> testClassSample) throws InitializationError {
    if (config != null) {
        // init has already been called, nothing to do
        return;
    }
    if (this.initFailed) {
        throw new InitializationError("Session initialization failed previously. Not trying again.");
    }
    try {
        config = new DriverConfiguration(testClassSample);
        addShutdownHook();
        // initialize the browser sessions
        initBrowsers();
        initBrowserDependencies();
        startBrowserDependencies();
        startBrowsers();
    } catch (Throwable e) {
        printStackTrace(e);
        reset();
        this.initFailed = true;
        // sometimes, JUnit doesn't display the exception, so let's print it out
        throw new InitializationError(e);
    }
}
Also used : InitializationError(org.junit.runners.model.InitializationError)

Example 32 with InitializationError

use of org.junit.runners.model.InitializationError in project st-js by st-js.

the class JUnitSession method printCauses.

private static void printCauses(Throwable caused, String prefix, PrintStream out) {
    if (caused instanceof InitializationError) {
        // Initialization error does not use the standard way to report causes, and therefore
        // printStackTrace() on InitializationError does not print causes. Let's try to fix that
        InitializationError ie = (InitializationError) caused;
        List<Throwable> causes = ie.getCauses();
        if (causes != null && !causes.isEmpty()) {
            System.err.println(prefix + "Caused by " + causes.size() + " exceptions:");
            for (Throwable cause : causes) {
                printCauseStackTrace(cause, caused.getStackTrace(), "\t" + prefix, out);
            }
        }
    } else if (caused.getCause() != null) {
        printCauseStackTrace(caused.getCause(), caused.getStackTrace(), prefix, out);
    }
}
Also used : InitializationError(org.junit.runners.model.InitializationError)

Example 33 with InitializationError

use of org.junit.runners.model.InitializationError in project vert.x by eclipse.

the class AsyncTestBaseTest method testReportLateFailures.

@Test
public void testReportLateFailures() {
    Result result;
    try {
        result = new JUnitCore().run(new BlockJUnit4ClassRunner(LateFailureReport.class));
    } catch (InitializationError initializationError) {
        throw new AssertionError(initializationError);
    }
    assertEquals(1, result.getFailureCount());
    assertEquals(IllegalStateException.class, result.getFailures().get(0).getException().getClass());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) InitializationError(org.junit.runners.model.InitializationError) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 34 with InitializationError

use of org.junit.runners.model.InitializationError in project xtext-eclipse 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.junit4.smoketest.Scenarios) Scenario(org.eclipse.xtext.junit4.smoketest.Scenario)

Example 35 with InitializationError

use of org.junit.runners.model.InitializationError in project drools-wb by kiegroup.

the class ScenarioRunnerService method run.

public TestScenarioResult run(final String identifier, final Scenario scenario, final KieModule module) {
    try {
        final HashMap<String, KieSession> ksessions = new HashMap<String, KieSession>();
        final String ksessionName = getKSessionName(scenario.getKSessions());
        ksessions.put(ksessionName, loadKSession(module, ksessionName));
        final AuditLogger auditLogger = new AuditLogger(ksessions);
        final ScenarioRunner4JUnit scenarioRunner = new ScenarioRunner4JUnit(scenario, ksessions, getMaxRuleFirings());
        final TestResultMessage testResultMessage = run(identifier, null, scenarioRunner);
        return new TestScenarioResult(scenario, auditLogger.getLog(), testResultMessage);
    } catch (InitializationError initializationError) {
        throw new GenericPortableException(initializationError.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) InitializationError(org.junit.runners.model.InitializationError) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) GenericPortableException(org.guvnor.common.services.shared.exceptions.GenericPortableException) KieSession(org.kie.api.runtime.KieSession) ScenarioRunner4JUnit(org.drools.workbench.models.testscenarios.backend.ScenarioRunner4JUnit) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult)

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