public void run( Scenario scenario, KieSession ksession, Event<TestResultMessage> testResultMessageEvent) { try { ScenarioRunner4JUnit scenarioRunner = new ScenarioRunner4JUnit(scenario, ksession); scenarioRunner.run(new CustomJUnitRunNotifier(testResultMessageEvent)); } catch (InitializationError initializationError) { throw new GenericPortableException(initializationError.getMessage()); } }
private List<Runner> runnersForClasses(List<Class<?>> allPossibleClasses) { // TODO: cheating ArrayList<Runner> result = new ArrayList<Runner>(); for (Class<?> each : allPossibleClasses) { try { result.add(new BlockJUnit4ClassRunner(each)); } catch (InitializationError e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
protected ExamplesRunner( Runtime runtime, CucumberExamples cucumberExamples, JUnitReporter jUnitReporter) throws InitializationError { super(ExamplesRunner.class, new ArrayList<Runner>()); this.cucumberExamples = cucumberExamples; List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios(); for (CucumberScenario scenario : exampleScenarios) { try { ExecutionUnitRunner exampleScenarioRunner = new ExecutionUnitRunner(runtime, scenario, jUnitReporter); getChildren().add(exampleScenarioRunner); } catch (InitializationError initializationError) { initializationError.printStackTrace(); } } }
private void handleInitializationError( final boolean developmentMode, final List<TestClassResult> result, final String klassName, final Class<?> klass, final InitializationError e) { TestClass testClass = new TestClass(klass); boolean allMethods = (!developmentMode) || (klass.getAnnotation(TestDuringDevelopment.class) != null); List<Throwable> causes = e.getCauses(); long now = System.currentTimeMillis(); List<TestCaseResult> testCaseResults = new ArrayList<TestCaseResult>(); List<FrameworkMethod> annotatedMethods = testClass.getAnnotatedMethods(Test.class); Exception wrapperException = new Exception("Error during initialization. See log for details"); wrapperException.setStackTrace(new StackTraceElement[0]); for (FrameworkMethod frameworkMethod : annotatedMethods) { if (allMethods || (frameworkMethod.getAnnotation(TestDuringDevelopment.class) != null)) { TestCaseResult testCaseResult = new TestCaseResult(frameworkMethod.getName(), now, now, wrapperException); testCaseResults.add(testCaseResult); } } TestClassResult classResult = new TestClassResult(klassName, 0, testCaseResults.size(), 0, 0, now, now, testCaseResults); result.add(classResult); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.write("Error during initialization of test class '" + klassName + "':\n"); for (Throwable throwable : causes) { throwable.printStackTrace(pw); } LOGGER.log(Level.SEVERE, sw.toString()); }
/** * Clients may override this method to add additional behavior when a {@link InitializationError} * is raised. The call of this method is guaranteed. * * @param notifier the notifier * @param e the error */ protected void whenInitializationErrorIsRaised( final EachTestNotifier notifier, final InitializationError e) { notifier.addFailure(new MultipleFailureException(e.getCauses())); }