final void run(final RunNotifier notifier) { RunNotifier nested = new RunNotifier(); NestedRunListener nestedListener = new NestedRunListener(notifier); nested.addListener(nestedListener); try { runEnabledTests(nested); } finally { nestedListener.cleanup(); } for (Description disabledTest : disabledTests) { nested.fireTestStarted(disabledTest); nested.fireTestIgnored(disabledTest); } }
@Override protected void runChild(Spec spec, RunNotifier notifier) { List<Spec> specs = spec.getSuite().getSpecs(); boolean suiteHasNoSpecs = specs.isEmpty(); boolean isFirstSpec = specs.indexOf(spec) == 0; boolean isLastSpec = specs.indexOf(spec) == specs.size() -1; if (suiteHasNoSpecs || isFirstSpec){ runBeforeCallbacks(spec); } if (spec.getBlock().isPresent()) { runBeforeEachCallbacks(spec); runLeaf(spec, describeChild(spec), notifier); runAfterEachCallbacks(spec); } else { notifier.fireTestIgnored(describeChild(spec)); } if (suiteHasNoSpecs || isLastSpec){ runAfterCallbacks(spec); } }
@Override protected void runChild(final ArchTestExecution child, final RunNotifier notifier) { ExpectedViolation expectedViolation = ExpectedViolation.none(); HandlingAssertion handlingAssertion = HandlingAssertion.none(); Description description = describeChild(child); notifier.fireTestStarted(description); try { ExpectedViolationDefinition violationDefinition = extractExpectedConfiguration(child); violationDefinition.configure(expectedViolation); violationDefinition.configure(handlingAssertion); expectedViolation.apply(new IntegrationTestStatement(child, handlingAssertion), description).evaluate(); } catch (Throwable throwable) { notifier.fireTestFailure(new Failure(description, throwable)); } finally { notifier.fireTestFinished(description); } }
@Override public void run(RunNotifier notifier) { final CourgetteRunner courgetteRunner = new CourgetteRunner(runnerInfoList, courgetteProperties); if (courgetteRunner.canRunFeatures()) { courgetteRunner.run(); courgetteRunner.createReport(); courgetteRunner.createCourgetteReport(); } if (courgetteRunner.allFeaturesPassed()) { System.exit(0x0); } else { courgetteRunner.createRerunFile(); System.exit(0x1); } }
@Override public void run(final RunNotifier notifier) { try { final File initialTempDir = FileUtil.getInitialTempDir(); final File rootTestDir = STROOMTestUtil.createRootTestDir(initialTempDir); final File testDir = STROOMTestUtil.createTestDir(rootTestDir); /* Redirect the temp dir for the tests. */ StroomProperties.setOverrideProperty(StroomProperties.STROOM_TEMP, testDir.getCanonicalPath(), "test"); FileUtil.forgetTempDir(); printTemp(); super.run(notifier); printTemp(); FileUtil.forceDelete(testDir); FileUtil.forgetTempDir(); StroomProperties.removeOverrides(); } catch (final Exception e) { throw new RuntimeException(e.getMessage(), e); } }
private void runChildren(@SuppressWarnings("hiding") final RunNotifier notifier) { RunnerScheduler currentScheduler = scheduler; try { List<Runner> roots = graph.getRoots().stream().map(r -> nameToRunner.get(r)).collect(Collectors.toList()); for (Runner each : roots) { currentScheduler.schedule(new Runnable() { @Override public void run() { ConcurrentDependsOnClasspathSuite.this.runChild(each, notifier); } }); } } finally { currentScheduler.finished(); } }
@Override protected void runChild(FeatureRunner featureRunner, RunNotifier notifier) { TestControl testControl = getTestClass().getJavaClass().getAnnotation(TestControl.class); ContainerAwareTestContext currentTestContext = new ContainerAwareTestContext(testControl, this.testContext); currentTestContext.applyBeforeFeatureConfig(getTestClass().getJavaClass()); try { super.runChild(featureRunner, notifier); } finally { currentTestContext.applyAfterFeatureConfig(); } }
/** * Run the tests in the supplied {@code testClass}, using the specified * {@link Runner}, and assert the expectations of the test execution. * * <p>If the specified {@code runnerClass} is {@code null}, the tests * will be run with the runner that the test class is configured with * (i.e., via {@link RunWith @RunWith}) or the default JUnit runner. * * @param runnerClass the explicit runner class to use or {@code null} * if the implicit runner should be used * @param testClass the test class to run with JUnit * @param expectedStartedCount the expected number of tests that started * @param expectedFailedCount the expected number of tests that failed * @param expectedFinishedCount the expected number of tests that finished * @param expectedIgnoredCount the expected number of tests that were ignored * @param expectedAssumptionFailedCount the expected number of tests that * resulted in a failed assumption */ public static void runTestsAndAssertCounters(Class<? extends Runner> runnerClass, Class<?> testClass, int expectedStartedCount, int expectedFailedCount, int expectedFinishedCount, int expectedIgnoredCount, int expectedAssumptionFailedCount) throws Exception { TrackingRunListener listener = new TrackingRunListener(); if (runnerClass != null) { Constructor<?> constructor = runnerClass.getConstructor(Class.class); Runner runner = (Runner) BeanUtils.instantiateClass(constructor, testClass); RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); runner.run(notifier); } else { JUnitCore junit = new JUnitCore(); junit.addListener(listener); junit.run(testClass); } assertEquals("tests started for [" + testClass + "]:", expectedStartedCount, listener.getTestStartedCount()); assertEquals("tests failed for [" + testClass + "]:", expectedFailedCount, listener.getTestFailureCount()); assertEquals("tests finished for [" + testClass + "]:", expectedFinishedCount, listener.getTestFinishedCount()); assertEquals("tests ignored for [" + testClass + "]:", expectedIgnoredCount, listener.getTestIgnoredCount()); assertEquals("failed assumptions for [" + testClass + "]:", expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount()); }
@Test public void shouldValidateUnsuccessfullyForInjectMocksPresence() throws Exception { // given RunNotifier notifier = mock(RunNotifier.class); TestClass testClass = new TestClass(getClass()); DelayedInjectionRunnerValidator validator = new DelayedInjectionRunnerValidator(notifier, testClass); Description description = mock(Description.class); // when validator.testFinished(description); // then ArgumentCaptor<Failure> captor = ArgumentCaptor.forClass(Failure.class); verify(notifier).fireTestFailure(captor.capture()); Failure failure = captor.getValue(); assertThat(failure.getMessage(), containsString("Do not use @InjectMocks")); }
@Override protected void runChild(FrameworkMethod method, RunNotifier notifier) { try { _baratine = new BaratineContainer(); _baratine.boot(true); super.runChild(method, notifier); } catch (RuntimeException e) { throw e; } catch (Throwable t) { throw new RuntimeException(t); } finally { _baratine.stop(); } }
@Override protected void runChild( final FrameworkMethod method, RunNotifier notifier ) { Description description = describeChild( method ); if ( method.getAnnotation( Ignore.class ) != null ) { notifier.fireTestIgnored( description ); } else { if ( method.getAnnotation( Repeat.class ) != null && method.getAnnotation( Ignore.class ) == null ) { retryCount = method.getAnnotation( Repeat.class ).retryCount(); sleepTime = method.getAnnotation( Repeat.class ).sleepTime(); } runTestUnit( methodBlock( method ), description, notifier ); } }
protected Statement prepareMethodBlock(final FrameworkMethod method, final RunNotifier notifier) { final Statement methodBlock = superMethodBlock(method); return new Statement() { @Override public void evaluate() throws Throwable { try { methodBlock.evaluate(); Description description = describeChild(method); try { notifier.fireTestStarted(description); notifier.fireTestAssumptionFailed(new Failure(description, new AssumptionViolatedException("Method " + method.getName() + " did parse any input"))); } finally { notifier.fireTestFinished(description); } } catch(TestDataCarrier testData) { AbstractParallelScenarioRunner.this.testData.put(method, testData.getData()); } } }; }
@Override protected void runChild(FrameworkMethod method, RunNotifier notifier) { Description description = describeChild(method); // check Ignore first if (method.getAnnotation(Ignore.class) != null) { notify("@Ignore", description); notifier.fireTestIgnored(description); } else if (localTestsEnabled && method.getAnnotation(RemoteOnly.class) != null) { // if running in local mode and @RemoteOnly annotation exists, ignore notify("Skip @RemoteOnly", description); notifier.fireTestIgnored(description); } else if (remoteTestsEnabled && method.getAnnotation(LocalOnly.class) != null) { // if running in remote mode and @LocalOnly annotation exists, ignore notify("Skip @LocalOnly", description); notifier.fireTestIgnored(description); } else { // default is run in either mode notify("Test[" + mode + "]", description); super.runChild(method, notifier); } }
@Override public void run(final RunNotifier rn) { System.out.println("Run is called!"); if (isMainThread() && runOtherThread()) { if (Utils.isMacOS()) { SwingAWTUtils.getDefaultToolkit(); // OS X workaround } runnerThread = new Thread(new Runnable() { @Override public void run() { OtherThreadRunner.super.run(rn); putPoison(); } }); runnerThread.start(); executeTasks(); } else { super.run(rn); } }
@Override protected void runChild(final FrameworkMethod method, final RunNotifier notifier) { try { try { ThreadScopeContextHolder.createContext(); final LogExecutionTime logExecutionTime = new LogExecutionTime(); try { runChildBefore(this, method, notifier); super.runChild(method, notifier); } finally { runChildAfter(this, method, notifier, logExecutionTime); } } finally { ThreadScopeContextHolder.destroyContext(); } } catch (final Exception e) { throw new RuntimeException(e.getMessage(), e); } ExternalShutdownController.shutdown(); }
@Override public void runChild(final FrameworkMethod method, final RunNotifier notifier) { final Description description = describeChild(method); if (this.isIgnored(method)) { notifier.fireTestIgnored(description); } else { EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description); eachNotifier.fireTestStarted(); boolean ignored = false; try { this.methodBlock(method).evaluate(); } catch (AssumptionViolatedException ave) { eachNotifier.addFailedAssumption(ave); } catch (Throwable e) { if (validateForGraphComputer(e)) { eachNotifier.fireTestIgnored(); logger.info(e.getMessage()); ignored = true; } else eachNotifier.addFailure(e); } finally { if (!ignored) eachNotifier.fireTestFinished(); } } }
/** * Runs the test corresponding to {@code child}, which can be assumed to be * an element of the list returned by {@link ParentRunner#getChildren()}. * Subclasses are responsible for making sure that relevant test events are * reported through {@code notifier} * * @param child * @param notifier */ @Override protected void runChild(ScenarioSpec child, RunNotifier notifier) { final Description description = Description.createTestDescription(testClass, child.getScenarioName()); // Notify that this single test has been started. // Supply the scenario/journey name notifier.fireTestStarted(description); passed = getInjectedMultiStepsRunner().runScenario(child, notifier, description); testRunCompleted = true; if (passed) { logger.info(String.format("\nPackageRunner- **FINISHED executing all Steps for [%s] **.\nSteps were:%s", child.getScenarioName(), child.getSteps().stream().map(step -> step.getName()).collect(Collectors.toList()))); } notifier.fireTestFinished(description); }
private void runChildren(@SuppressWarnings("hiding") final RunNotifier notifier) { RunnerScheduler currentScheduler = scheduler; try { List<FrameworkMethod> roots = graph.getRoots().stream().map(r -> nameToMethod.get(r)).collect(Collectors.toList()); for (FrameworkMethod each : roots) { currentScheduler.schedule(new Runnable() { @Override public void run() { ConcurrentDependsOnRunner.this.runChild(each, notifier); } }); } } finally { currentScheduler.finished(); } }
@Override public void run(RunNotifier notifier) { initDescription(); for (Execution execution : executions) { execution.run(notifier); } }
private void runEnabledTests(RunNotifier nested) { if (enabledTests.isEmpty()) { return; } Runner runner; try { runner = createExecutionRunner(); } catch (Throwable t) { runner = new CannotExecuteRunner(getDisplayName(), target, t); } try { if (!disabledTests.isEmpty()) { ((Filterable) runner).filter(new Filter() { @Override public boolean shouldRun(Description description) { return !disabledTests.contains(description); } @Override public String describe() { return "disabled tests"; } }); } } catch (NoTestsRemainException e) { return; } runner.run(nested); }
@Override public void run(RunNotifier notifier) { Description description = getDescription(); notifier.fireTestStarted(description); notifier.fireTestFailure(new Failure(description, failure)); notifier.fireTestFinished(description); }
@Override protected void runChild(FrameworkMethod method, RunNotifier notifier) { try { super.runChild(method, notifier); } finally { shutdownInstanceFor(method); } }
@Override public void run(final RunNotifier notifier) { try { super.run(notifier); } finally { testSetup.shutdown(); } }
@Override protected Statement childrenInvoker(final RunNotifier notifier) { childrenFinish = new CountDownLatch(getChildren().size()); return new Statement() { @Override public void evaluate() throws Throwable { MultiThreadRunner.super.childrenInvoker(notifier).evaluate(); childrenFinish.await(); } }; }
@After("execution(org.junit.runner.notification.RunNotifier.new())") public void addListener(final JoinPoint point) { final RunNotifier notifier = (RunNotifier) point.getThis(); notifier.removeListener(allure); notifier.addListener(allure); }
/** * Méthode takeScreenShot. * @throws SaladiumException */ public String takeScreenShot() { String pathScreenShot = ""; try { String capturePath = AbstractWorker.capturePath; File scrFile = ((TakesScreenshot) this).getScreenshotAs(OutputType.FILE); FileUtil.upload(scrFile.getAbsolutePath(), capturePath + "/" + scrFile.getName()); pathScreenShot = capturePath + "/" + scrFile.getName(); this.logger.info("ScreenShot effectué" + pathScreenShot); } catch (Exception e1) { this.logger.info("takeScreenShot échoué"); e1.printStackTrace(); } // try { // // déconnexion // By decoLocator = By.cssSelector("#logoff > a"); // WebElement webElement = wait.until(ExpectedConditions.elementToBeClickable(decoLocator)); // webElement.click(); // } catch (TimeoutException e) { // Assert.fail("Tentative de forçage de déconnexion après un sreenshot échouée"); // } // A activer si vous souhaitez arrêter les tests dès le premier screenshot effectué (idéal en mode dev ou debug) RunNotifier notifier = new RunNotifier(); Result result = new Result(); RunListener listener = result.createListener(); notifier.addFirstListener(listener); notifier.pleaseStop(); return pathScreenShot; }
@Override protected void runChild(TestCases.TestCase testCase, RunNotifier runNotifier) { Description description = this.children.get( testCase ); try { runNotifier.fireTestStarted( description ); vendorSuite.beforeTest( description, context, testCase ); TestResult result = vendorSuite.executeTest( description, context, testCase ); switch ( result.getResult() ) { case SUCCESS: runNotifier.fireTestFinished( description ); break; case IGNORED: runNotifier.fireTestIgnored( description ); break; case ERROR: runNotifier.fireTestFailure(new Failure(description, new RuntimeException(result.toStringWithLines()))); break; } if (resultFile != null) { String relativePath = relativePath(folder); resultFile.append( String.format( "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n", relativePath, description.getClassName(), description.getMethodName(), result.getResult().toString(), result.getMsg() ) ); } } catch ( IOException e ) { e.printStackTrace(); } finally { vendorSuite.afterTest( description, context, testCase ); runNotifier.fireTestFinished(description); } }
@Test public void itExecutesBeforeHandlersBeforeTheFirstSpecIsExecuted() { suite.addBeforeHandler(block.apply("before")); suite.addSpec(first); suite.addSpec(second); runner.runChild(first, new RunNotifier()); runner.runChild(second, new RunNotifier()); assertEquals(Arrays.asList("before", "first-spec", "second-spec"), calls); }
@Test public void itExecutesAfterHandlersOnceAfterTheLastSpecIsExecuted() { suite.addAfterHandler(block.apply("after")); suite.addSpec(first); suite.addSpec(second); runner.runChild(first, new RunNotifier()); runner.runChild(second, new RunNotifier()); assertEquals(Arrays.asList("first-spec", "second-spec", "after"), calls); }
@Test public void itExecutesOuterBeforeHandlersBeforeInnerOnes() { suite.addBeforeHandler(block.apply("outerBefore")); Suite child = new Suite(suite, "child"); child.addBeforeHandler(block.apply("innerBefore")); runner.runChild(new Spec(child, "spec", Optional.of(block.apply("spec"))), new RunNotifier()); assertEquals(Arrays.asList("outerBefore", "innerBefore", "spec"), calls); }
@Test public void itExecutesBeforeHandlersInSpecifiedOrder() { suite.addBeforeHandler(block.apply("first")); suite.addBeforeHandler(block.apply("second")); runner.runChild(spec, new RunNotifier()); assertEquals(Arrays.asList("first", "second", "spec"), calls); }
@Test public void itExecutesBeforeEachHandlersInSpecifiedOrder() { suite.addBeforeEachHandler(block.apply("first")); suite.addBeforeEachHandler(block.apply("second")); runner.runChild(new Spec(suite, "spec", Optional.of(() -> {})), new RunNotifier()); assertEquals(Arrays.asList("first", "second"), calls); }
@Test public void itExecutesAfterEachHandlersInSpecifiedOrder() { suite.addAfterEachHandler(block.apply("first")); suite.addAfterEachHandler(block.apply("second")); runner.runChild(new Spec(suite, "spec", Optional.of(() -> {})), new RunNotifier()); assertEquals(Arrays.asList("first", "second"), calls); }
@Test public void itExecutesOuterBeforeEachHandlersBeforeInnerOnes() { suite.addBeforeEachHandler(block.apply("outerBeforeEach")); Suite child = new Suite(suite, "child"); child.addBeforeEachHandler(block.apply("innerBeforeEach")); runner.runChild(new Spec(child, "spec", Optional.of(() -> {})), new RunNotifier()); assertEquals(Arrays.asList("outerBeforeEach", "innerBeforeEach"), calls); }
@Test public void itExecutesInnerAfterEachHandlersBeforeOuterOnes() { suite.addAfterEachHandler(block.apply("outerBeforeEach")); Suite child = new Suite(suite, "child"); child.addAfterEachHandler(block.apply("innerBeforeEach")); runner.runChild(new Spec(child, "spec", Optional.of(() -> {})), new RunNotifier()); assertEquals(Arrays.asList("innerBeforeEach", "outerBeforeEach"), calls); }
@Override protected void runChild(Object object, RunNotifier runNotifier) { try { Method method = ParentRunner.class.getDeclaredMethod("runChild", Object.class, RunNotifier.class); method.setAccessible(true); method.invoke(oleasterRobolectricRunner, object, runNotifier); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } }
@Override public void run(RunNotifier notifier) { super.run(notifier); if (reporter != null) { // can happen for zero features found reporter.done(); reporter.close(); } }
@Override public void render() { synchronized (invokeInRender) { for (Map.Entry<FrameworkMethod, RunNotifier> each : invokeInRender.entrySet()) { super.runChild(each.getKey(), each.getValue()); } invokeInRender.clear(); } }
@Override protected void runChild(FrameworkMethod method, RunNotifier notifier) { synchronized (invokeInRender) { // add for invoking in render phase, where gl context is available invokeInRender.put(method, notifier); } // wait until that test was invoked waitUntilInvokedInRenderMethod(); }
private void testJSJVMBackendFrameworkMethod(FrameworkMethod aFrameworkMethod, RunNotifier aRunNotifier) { Description theDescription = Description.createTestDescription(testClass.getJavaClass(), aFrameworkMethod.getName() + " JVM Target"); aRunNotifier.fireTestStarted(theDescription); try { // Simply invoke using reflection Object theInstance = testClass.getJavaClass().getDeclaredConstructor().newInstance(); Method theMethod = aFrameworkMethod.getMethod(); theMethod.invoke(theInstance); aRunNotifier.fireTestFinished(theDescription); } catch (Exception e) { aRunNotifier.fireTestFailure(new Failure(theDescription, e)); } }