org.junit.runner.notification.RunListener Java Examples
The following examples show how to use
org.junit.runner.notification.RunListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RunUntilFailure.java From phoenix with Apache License 2.0 | 6 votes |
private void runRepeatedly(Statement statement, Description description, RunNotifier notifier) { notifier.addListener(new RunListener() { @Override public void testFailure(Failure failure) { hasFailure = true; } }); for (Description desc : description.getChildren()) { if (hasFailure) { notifier.fireTestIgnored(desc); } else if(!desc.isSuite()) { runLeaf(statement, desc, notifier); } } }
Example #2
Source File: SquidbTestRunner.java From squidb with Apache License 2.0 | 6 votes |
/** * Runs the test classes given in {@param classes}. * * @returns Zero if all tests pass, non-zero otherwise. */ public static int run(Class[] classes, RunListener listener, PrintStream out) { JUnitCore junitCore = new JUnitCore(); junitCore.addListener(listener); boolean hasError = false; int numTests = 0; int numFailures = 0; long start = System.currentTimeMillis(); for (@AutoreleasePool Class c : classes) { out.println("Running " + c.getName()); Result result = junitCore.run(c); numTests += result.getRunCount(); numFailures += result.getFailureCount(); hasError = hasError || !result.wasSuccessful(); } long end = System.currentTimeMillis(); out.println(String.format("Ran %d tests, %d failures. Total time: %s seconds", numTests, numFailures, NumberFormat.getInstance().format((double) (end - start) / 1000))); return hasError ? 1 : 0; }
Example #3
Source File: JUnit4RunnerFactory.java From bazel with Apache License 2.0 | 6 votes |
public static Factory<JUnit4Runner> create( Supplier<Request> requestSupplier, Supplier<CancellableRequestFactory> requestFactorySupplier, Supplier<Supplier<TestSuiteModel>> modelSupplierSupplier, Supplier<PrintStream> testRunnerOutSupplier, Supplier<JUnit4Config> configSupplier, Supplier<Set<RunListener>> runListenersSupplier, Supplier<Set<JUnit4Runner.Initializer>> initializersSupplier) { return new JUnit4RunnerFactory( requestSupplier, requestFactorySupplier, modelSupplierSupplier, testRunnerOutSupplier, configSupplier, runListenersSupplier, initializersSupplier); }
Example #4
Source File: WebTesterJUnitRunnerTest.java From webtester2-core with Apache License 2.0 | 6 votes |
private static void executeTestClass(Class<?> testClass) throws Throwable { Throwable[] throwables = new Throwable[1]; WebTesterJUnitRunner runner = new WebTesterJUnitRunner(testClass); RunNotifier notifier = new RunNotifier(); notifier.addListener(new RunListener() { public void testFailure(Failure failure) throws Exception { System.out.println("testFailure"); throwables[0] = failure.getException(); } }); runner.run(notifier); if (throwables[0] != null) { throw throwables[0]; } }
Example #5
Source File: BundleJUnitUtilsTest.java From android-test with Apache License 2.0 | 6 votes |
@Test public void fromResult_success() throws Exception { Class<SampleJUnitTest> testClass = SampleJUnitTest.class; Description jUnitDescription = Description.createTestDescription(testClass, "sampleTest"); Result jUnitResult = new Result(); RunListener jUnitListener = jUnitResult.createListener(); jUnitListener.testRunStarted(jUnitDescription); jUnitListener.testStarted(jUnitDescription); jUnitListener.testFinished(jUnitDescription); ParcelableResult parcelableResult = BundleJUnitUtils.getResult(parcelBundle(BundleJUnitUtils.getBundleFromResult(jUnitResult))); assertThat(parcelableResult.wasSuccessful(), is(jUnitResult.wasSuccessful())); }
Example #6
Source File: ConsoleSpammingMockitoJUnitRunner.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public void run(RunNotifier notifier) { RunListener listener = new RunListener() { WarningsCollector warningsCollector; @Override public void testStarted(Description description) throws Exception { warningsCollector = new WarningsCollector(); } @Override public void testFailure(Failure failure) throws Exception { logger.log(warningsCollector.getWarnings()); } }; notifier.addListener(listener); runner.run(notifier); }
Example #7
Source File: VerboseMockitoJUnitRunner.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public void run(RunNotifier notifier) { //a listener that changes the failure's exception in a very hacky way... RunListener listener = new RunListener() { WarningsCollector warningsCollector; @Override public void testStarted(Description description) throws Exception { warningsCollector = new WarningsCollector(); } @Override public void testFailure(final Failure failure) throws Exception { String warnings = warningsCollector.getWarnings(); new JUnitFailureHacker().appendWarnings(failure, warnings); } }; notifier.addFirstListener(listener); runner.run(notifier); }
Example #8
Source File: ConsoleSpammingMockitoJUnitRunner.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public void run(RunNotifier notifier) { RunListener listener = new RunListener() { WarningsCollector warningsCollector; @Override public void testStarted(Description description) throws Exception { warningsCollector = new WarningsCollector(); } @Override public void testFailure(Failure failure) throws Exception { logger.log(warningsCollector.getWarnings()); } }; notifier.addListener(listener); runner.run(notifier); }
Example #9
Source File: WebTauRunner.java From webtau with Apache License 2.0 | 6 votes |
@Override protected void runChild(FrameworkMethod method, RunNotifier notifier) { JavaBasedTest javaBasedTest = createJavaBasedTest(method); WebTauTest webTauTest = javaBasedTest.getTest(); notifier.addListener(new RunListener() { @Override public void testFailure(Failure failure) { webTauTest.setExceptionIfNotSet(failure.getException()); } }); beforeTestRun(javaBasedTest); try { super.runChild(method, notifier); } catch (Throwable e) { webTauTest.setExceptionIfNotSet(e); throw e; } finally { afterTestRun(javaBasedTest); } }
Example #10
Source File: DelegateRunNotifier.java From buck with Apache License 2.0 | 6 votes |
DelegateRunNotifier(Runner runner, RunNotifier delegate, long defaultTestTimeoutMillis) { this.runner = runner; this.delegate = delegate; this.finishedTests = new HashSet<Description>(); this.defaultTestTimeoutMillis = defaultTestTimeoutMillis; this.timer = new Timer(); this.hasTestThatExceededTimeout = new AtomicBoolean(false); // Because our fireTestRunFinished() does not seem to get invoked, we listen for the // delegate to fire a testRunFinished event so we can dispose of the timer. delegate.addListener( new RunListener() { @Override public void testRunFinished(Result result) { onTestRunFinished(); } }); }
Example #11
Source File: DefaultServer.java From quarkus-http with Apache License 2.0 | 6 votes |
private static void runInternal(final RunNotifier notifier) { if (openssl && OPENSSL_FAILURE != null) { throw new RuntimeException(OPENSSL_FAILURE); } if (first) { first = false; undertow = Undertow.builder() .setHandler(rootHandler) .addHttpListener(getHostPort(DEFAULT), getHostAddress(DEFAULT)) .build(); undertow.start(); notifier.addListener(new RunListener() { @Override public void testRunFinished(Result result) throws Exception { super.testRunFinished(result); undertow.stop(); clientGroup.shutdownGracefully(); } }); } }
Example #12
Source File: KurentoRunNotifier.java From kurento-java with Apache License 2.0 | 5 votes |
@Override public void fireTestFinished(final Description description) { new SafeNotifier() { @Override protected void notifyListener(RunListener each) throws Exception { each.testFinished(description); exception = null; } }.run(); }
Example #13
Source File: TestCommitRevertRunner.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
@Override public void run(RunNotifier notifier) { RunListener l = new RunListener() { public void testRunFinished(Result result) throws Exception { super.testRunFinished(result); GitCommitOrRevert.doCommitOrRevert(result.getFailureCount()); } }; notifier.addListener(l); super.run(notifier); }
Example #14
Source File: MarathonTestRunner.java From marathonv5 with Apache License 2.0 | 5 votes |
/** * Do not use. Testing purposes only. */ public Result run(org.junit.runner.Runner runner) { Result result = new Result(); RunListener listener = result.createListener(); notifier.addFirstListener(listener); try { notifier.fireTestRunStarted(runner.getDescription()); runner.run(notifier); notifier.fireTestRunFinished(result); } finally { removeListener(listener); } return result; }
Example #15
Source File: JpaUnitRunnerTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testClassWithPersistenceContextAndPersistenceUnitFields() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class); jAnnotationUse.param("value", JpaUnitRunner.class); final JFieldVar emf1Field = jClass.field(JMod.PRIVATE, EntityManager.class, "em"); emf1Field.annotate(PersistenceContext.class); final JFieldVar emf2Field = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf"); emf2Field.annotate(PersistenceUnit.class); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); final JpaUnitRunner runner = new JpaUnitRunner(cut); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class); verify(listener).testFailure(failureCaptor.capture()); final Failure failure = failureCaptor.getValue(); assertThat(failure.getException().getClass(), equalTo(IllegalArgumentException.class)); assertThat(failure.getException().getMessage(), containsString("either @PersistenceUnit or @PersistenceContext")); }
Example #16
Source File: JUnit4RunnerTest.java From bazel with Apache License 2.0 | 5 votes |
@Test public void testPassingTest() throws Exception { config = createConfig(); mockRunListener = mock(RunListener.class); JUnit4Runner runner = createRunner(SamplePassingTest.class); Description testDescription = Description.createTestDescription(SamplePassingTest.class, "testThatAlwaysPasses"); Description suiteDescription = Description.createSuiteDescription(SamplePassingTest.class); suiteDescription.addChild(testDescription); Result result = runner.run(); assertThat(result.getRunCount()).isEqualTo(1); assertThat(result.getFailureCount()).isEqualTo(0); assertThat(result.getIgnoreCount()).isEqualTo(0); assertPassingTestHasExpectedOutput(stdoutByteStream, SamplePassingTest.class); InOrder inOrder = inOrder(mockRunListener); inOrder.verify(mockRunListener).testRunStarted(suiteDescription); inOrder.verify(mockRunListener).testStarted(testDescription); inOrder.verify(mockRunListener).testFinished(testDescription); inOrder.verify(mockRunListener).testRunFinished(any(Result.class)); }
Example #17
Source File: TestSuiteExecution.java From nopol with GNU General Public License v2.0 | 5 votes |
public static CompoundResult runTestResult(Collection<TestResult> testCases, ClassLoader classLoaderForTestThread, RunListener listener, NopolContext nopolContext) { List<Result> results = MetaList.newArrayList(testCases.size()); for (TestResult testCase : testCases) { if (testCase.getTestCase().className().startsWith("junit.")) { continue; } String completeTestName = testCase.getTestCase().className()+"#"+testCase.getTestCase().testName(); if (!nopolContext.getTestMethodsToIgnore().contains(completeTestName)) { results.add(runTestCase(testCase, classLoaderForTestThread, listener, nopolContext)); } } return new CompoundResult(results); }
Example #18
Source File: TestSuiteExecution.java From nopol with GNU General Public License v2.0 | 5 votes |
public static CompoundResult runTestCases(Collection<TestCase> testCases, ClassLoader classLoaderForTestThread, RunListener listener, NopolContext nopolContext) { List<Result> results = MetaList.newArrayList(testCases.size()); for (TestCase testCase : testCases) { String completeTestName = testCase.className()+"#"+testCase.testName(); if (!nopolContext.getTestMethodsToIgnore().contains(completeTestName)) { results.add(runTestCase(testCase, classLoaderForTestThread, listener, nopolContext)); } } return new CompoundResult(results); }
Example #19
Source File: JUnitTestClassExecuter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public JUnitTestClassExecuter(ClassLoader applicationClassLoader, JUnitSpec spec, RunListener listener, TestClassExecutionListener executionListener) { assert executionListener instanceof ThreadSafe; this.applicationClassLoader = applicationClassLoader; this.listener = listener; this.options = spec; this.executionListener = executionListener; }
Example #20
Source File: JUnitTestClassExecuter.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public JUnitTestClassExecuter(ClassLoader applicationClassLoader, JUnitSpec spec, RunListener listener, TestClassExecutionListener executionListener) { assert executionListener instanceof ThreadSafe; this.applicationClassLoader = applicationClassLoader; this.listener = listener; this.options = spec; this.executionListener = executionListener; }
Example #21
Source File: TestSuiteExecutor.java From dekaf with Apache License 2.0 | 5 votes |
public static void run(final Class... suites) { boolean underTC = System.getenv(TEAMCITY_DETECT_VAR_NAME) != null; // prepare junit JUnitSystem system = new RealSystem(); JUnitCore core = new JUnitCore(); RunListener listener = underTC ? new TeamCityListener() : new TextListener(system); core.addListener(listener); int success = 0, failures = 0, ignores = 0; // run tests for (Class suite : suites) { sayNothing(); String suiteName = suite.getSimpleName(); if (suiteName.endsWith("Tests")) suiteName = suiteName.substring(0, suiteName.length()-"Tests".length()); if (suiteName.endsWith("Integration")) suiteName = suiteName.substring(0, suiteName.length()-"Integration".length()); if (suiteParameter != null) suiteName = suiteName + '[' + suiteParameter + ']'; if (underTC) say("##teamcity[testSuiteStarted name='%s']", suiteName); Result result = core.run(suite); success += result.getRunCount() - (result.getFailureCount() + result.getIgnoreCount()); failures += result.getFailureCount(); ignores += result.getIgnoreCount(); if (underTC) say("##teamcity[testSuiteFinished name='%s']", suiteName); sayNothing(); } }
Example #22
Source File: TestExecutor.java From android-test with Apache License 2.0 | 5 votes |
/** Initialize listeners and add them to the JUnitCore runner */ private void setUpListeners(JUnitCore testRunner) { for (RunListener listener : listeners) { Log.d(LOG_TAG, "Adding listener " + listener.getClass().getName()); testRunner.addListener(listener); if (listener instanceof InstrumentationRunListener) { ((InstrumentationRunListener) listener).setInstrumentation(instr); } } }
Example #23
Source File: TestExecutor.java From android-test with Apache License 2.0 | 5 votes |
private void reportRunEnded( List<RunListener> listeners, PrintStream summaryWriter, Bundle resultBundle, Result jUnitResults) { for (RunListener listener : listeners) { if (listener instanceof InstrumentationRunListener) { ((InstrumentationRunListener) listener) .instrumentationRunFinished(summaryWriter, resultBundle, jUnitResults); } } }
Example #24
Source File: TestModuleMockRunListenerFactory.java From bazel with Apache License 2.0 | 5 votes |
@Override public Set<RunListener> get() { Set<RunListener> runListeners = module.mockRunListener(); if (runListeners == null) { throw new NullPointerException(); } return runListeners; }
Example #25
Source File: ParameterizedSWTBotRunner.java From editorconfig-eclipse with Apache License 2.0 | 5 votes |
@Override public void run(final RunNotifier notifier) { final RunListener failureSpy = new ScreenshotCaptureListener(); notifier.removeListener(failureSpy); // remove existing listeners that could be added by suite or class runners notifier.addListener(failureSpy); try { super.run(notifier); } finally { notifier.removeListener(failureSpy); } }
Example #26
Source File: WildFlyTestRunner.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void run(final RunNotifier notifier) { notifier.addListener(new RunListener() { @Override public void testRunFinished(Result result) throws Exception { super.testRunFinished(result); server.stop(); } }); server.start(); super.run(notifier); }
Example #27
Source File: WildflyTestRunner.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void run(final RunNotifier notifier) { notifier.addListener(new RunListener() { @Override public void testRunFinished(Result result) throws Exception { super.testRunFinished(result); parameterDescriptions.clear(); if (automaticServerControl) { controller.stop(); } } }); configureTestRun(); if (!serverSetupTasks.isEmpty() && !automaticServerControl) { throw new RuntimeException("Can't run setup tasks with manual server control"); } boolean providerInstalled = false; if (Security.getProvider(ELYTRON_PROVIDER.getName()) == null) { Security.insertProviderAt(ELYTRON_PROVIDER, 0); providerInstalled = true; } if (automaticServerControl) { runSetupTasks(); } super.run(notifier); if (automaticServerControl) { runTearDownTasks(); } if (providerInstalled) { Security.removeProvider(ELYTRON_PROVIDER.getName()); } }
Example #28
Source File: JUnitTestRunner.java From j2objc with Apache License 2.0 | 5 votes |
/** * Runs the test classes given in {@param classes}. * @returns Zero if all tests pass, non-zero otherwise. */ public static int run(Class<?>[] classes, RunListener listener) { JUnitCore junitCore = new JUnitCore(); junitCore.addListener(listener); boolean hasError = false; for (@AutoreleasePool Class<?> c : classes) { Result result = junitCore.run(c); hasError = hasError || !result.wasSuccessful(); } return hasError ? 1 : 0; }
Example #29
Source File: JUnitTestRunner.java From j2objc with Apache License 2.0 | 5 votes |
/** * Runs the test classes that match settings in {@link #PROPERTIES_FILE_NAME}. * @returns Zero if all tests pass, non-zero otherwise. */ public int run() { if (outputFormat == OutputFormat.GTM_UNIT_TESTING) { Thread.setDefaultUncaughtExceptionHandler(new GtmUncaughtExceptionHandler()); } Set<Class<?>> classesSet = getTestClasses(); Class<?>[] classes = classesSet.toArray(new Class<?>[classesSet.size()]); sortClasses(classes, sortOrder); RunListener listener = newRunListener(outputFormat); return run(classes, listener); }
Example #30
Source File: JUnitTestRunner.java From j2objc with Apache License 2.0 | 5 votes |
/** * Returns a new {@link RunListener} instance for the given {@param outputFormat}. */ public RunListener newRunListener(OutputFormat outputFormat) { switch (outputFormat) { case JUNIT: out.println("JUnit version " + Version.id()); return new TextListener(out); case GTM_UNIT_TESTING: return new GtmUnitTestingTextListener(); default: throw new IllegalArgumentException("outputFormat"); } }