public RunNotifier getNotifier(final TestResult result, final JUnit4TestAdapter adapter) { RunNotifier notifier = new RunNotifier(); notifier.addListener(new RunListener() { @Override public void testFailure(Failure failure) throws Exception { result.addError(asTest(failure.getDescription()), failure.getException()); } @Override public void testFinished(Description description) throws Exception { result.endTest(asTest(description)); } @Override public void testStarted(Description description) throws Exception { result.startTest(asTest(description)); } }); return notifier; }
public RunNotifier getNotifier(final TestResult result, final JUnit4TestAdapter adapter) { RunNotifier notifier = new RunNotifier(); notifier.addListener(new RunListener() { @Override public void testFailure(Failure failure) throws Exception { result.addError(asTest(failure.getDescription()), failure.getException()); } @Override public void testFinished(Description description) throws Exception { result.endTest(asTest(description)); } @Override public void testStarted(Description description) throws Exception { result.startTest(asTest(description)); } }); return notifier; }
@Before public void setUp() throws Exception { notifier = new RunNotifier(); events = new ArrayList<>(); notifier.addListener(new MyRunListener()); priorEnabledSdks = System.getProperty("robolectric.enabledSdks"); System.clearProperty("robolectric.enabledSdks"); priorAlwaysInclude = System.getProperty("robolectric.alwaysIncludeVariantMarkersInTestName"); System.clearProperty("robolectric.alwaysIncludeVariantMarkersInTestName"); sdkCollection = new SdkCollection(new DefaultSdkProvider(null)); }
@Before public void setUp() { numSupportedApis = APIS_FOR_TEST.length; runListener = new MyRunListener(); runNotifier = new RunNotifier(); runNotifier.addListener(runListener); sdkCollection = new SdkCollection(() -> map(APIS_FOR_TEST)); delegateSdkPicker = new DefaultSdkPicker(sdkCollection, null); priorResourcesMode = System.getProperty("robolectric.resourcesMode"); System.setProperty("robolectric.resourcesMode", "legacy"); priorAlwaysInclude = System.getProperty("robolectric.alwaysIncludeVariantMarkersInTestName"); System.clearProperty("robolectric.alwaysIncludeVariantMarkersInTestName"); }
@Test public void shouldReleaseAllStateAfterClassSoWeDontLeakMemory() throws Exception { final List<RobolectricTestRunner.RobolectricFrameworkMethod> methods = new ArrayList<>(); RobolectricTestRunner robolectricTestRunner = new Runner(SimpleTest.class) { @Override protected void finallyAfterTest(FrameworkMethod method) { super.finallyAfterTest(method); RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method; assertThat(roboMethod.parallelUniverseInterface).isNull(); assertThat(roboMethod.testLifecycle).isNull(); methods.add(roboMethod); } }; robolectricTestRunner.run(new RunNotifier()); assertThat(methods).isNotEmpty(); }
@Nonnull public static List<Failure> runTests(Class<?> testClass) throws InitializationError { RunNotifier notifier = new RunNotifier(); FailureListener failureListener = new FailureListener(); notifier.addListener(failureListener); new RobolectricTestRunner(testClass).run(notifier); return failureListener.failures; }
private Result run(Runner runner) throws InitializationError { RunNotifier notifier = new RunNotifier(); Result result = new Result(); notifier.addListener(result.createListener()); runner.run(notifier); return result; }
private List<String> runAndGetFailures(Class<TestWithConfig> testClass) throws InitializationError { RunNotifier notifier = new RunNotifier(); FailureListener failureListener = new FailureListener(); notifier.addListener(failureListener); HierarchicalConfigurationStrategy configurationStrategy = new HierarchicalConfigurationStrategy( new ConfigConfigurer(new PackagePropertiesLoader()), new SomeConfigConfigurer()); SingleSdkRobolectricTestRunner testRunner = new SingleSdkRobolectricTestRunner( testClass, SingleSdkRobolectricTestRunner.defaultInjector() .bind(ConfigurationStrategy.class, configurationStrategy) .build()); testRunner.run(notifier); return failureListener.failures.stream().map(Failure::getMessage).collect(toList()); }
Constructor<?> constructor = runnerClass.getConstructor(Class.class); Runner runner = (Runner) BeanUtils.instantiateClass(constructor, testClass); RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); runner.run(notifier);
public RunNotifier getNotifier(final TestResult result, final JUnit4TestAdapter adapter) { RunNotifier notifier = new RunNotifier(); notifier.addListener(new RunListener() { @Override public void testFailure(Failure failure) throws Exception { result.addError(asTest(failure.getDescription()), failure.getException()); } @Override public void testFinished(Description description) throws Exception { result.endTest(asTest(description)); } @Override public void testStarted(Description description) throws Exception { result.startTest(asTest(description)); } }); return notifier; }
public void run() { final RunNotifier rn = new RunNotifier(); final RunListener listener = new AdaptingRunListener(this.description, this.rc); rn.addFirstListener(listener); this.runner.run(rn); }
@Override public Object invokeExplosively(final Object target, final Object... params) throws Throwable { instance.delegate.performInternalCucumberOperations(target, notifier == null ? new RunNotifier() : notifier); return null; }
public void run() { final RunNotifier rn = new RunNotifier(); final RunListener listener = new AdaptingRunListener(this.description, this.rc); rn.addFirstListener(listener); this.runner.run(rn); }
private static Object runExample(Example e) { Result result= new Result(); RunNotifier notifier = new RunNotifier(); notifier.addFirstListener(result.createListener()); e.run(notifier); if (!e.wasSuccessful()) { if (result.getFailures().size() != 1) throw new RuntimeException("Oops, what do we now!?"); throw new RuntimeException(result.getFailures().iterator().next().getException()); } return e.getReturnValue().getValue(); }
private RunNotifier initializeRunNotifier(RunNotifier notifier) { RunNotifier notifierForSteps = new RunNotifier(); notifierForSteps.addListener(getStepListener()); return (shouldRetryTest() ? notifier : new RetryFilteringRunNotifier(notifier, notifierForSteps)); }
public void runTests(Class<?>... testClasses) throws Exception { result = new Result(); RunNotifier runNotifier = new RunNotifier(); runNotifier.addListener(result.createListener()); for (Class<?> testClass : testClasses) { UnitilsJUnit4TestClassRunner testClassRunner = new TestUnitilsJUnit4TestClassRunner(testClass); testClassRunner.run(runNotifier); } }
public void runTest(final Sputnik spockRunner, final Result testResult) { final RunNotifier notifier = new RunNotifier(); notifier.addFirstListener(testResult.createListener()); for (RunListener listener : getRunListeners()) { notifier.addListener(listener); } spockRunner.run(notifier); }
@Test public void notifies_failure_when_different_exception_occurs() throws Throwable { J8SpecRunner runner = new J8SpecRunner(SampleSpec.class); List<Example> examples = runner.getChildren(); doThrow(new RuntimeException()).when(block(BLOCK_4)).tryToExecute(); RunNotifier runNotifier = new RunNotifier(); RunListenerHelper listener = new RunListenerHelper(); runNotifier.addListener(listener); runner.runChild(examples.get(3), runNotifier); assertThat(listener.getDescription(), is(runner.describeChild(examples.get(3)))); assertThat(listener.getException(), instanceOf(Exception.class)); }
@Test public void notifies_when_a_child_is_ignored() throws Throwable { J8SpecRunner runner = new J8SpecRunner(SampleSpec.class); List<Example> examples = runner.getChildren(); RunNotifier runNotifier = new RunNotifier(); RunListenerHelper listener = new RunListenerHelper(); runNotifier.addListener(listener); runner.runChild(examples.get(2), runNotifier); assertThat(listener.getDescription(), is(runner.describeChild(examples.get(2)))); assertThat(listener.isIgnored(), is(true)); verify(block(BLOCK_3), never()).tryToExecute(); }
@Test public void notifies_failure_when_example_times_out() throws InitializationError { J8SpecRunner runner = new J8SpecRunner(SampleSpec.class); List<Example> examples = runner.getChildren(); RunNotifier runNotifier = new RunNotifier(); RunListenerHelper listener = new RunListenerHelper(); runNotifier.addListener(listener); runner.runChild(examples.get(6), runNotifier); assertThat(listener.getDescription(), is(runner.describeChild(examples.get(6)))); assertThat(listener.getException(), instanceOf(TestTimedOutException.class)); } }