Java Code Examples for org.junit.runner.notification.RunNotifier#fireTestFailure()
The following examples show how to use
org.junit.runner.notification.RunNotifier#fireTestFailure() .
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: BytecoderUnitTestRunner.java From Bytecoder with Apache License 2.0 | 6 votes |
private void testJVMBackendFrameworkMethod(final FrameworkMethod aFrameworkMethod, final RunNotifier aRunNotifier) { if ("".equals(System.getProperty("BYTECODER_DISABLE_JVMTESTS", ""))) { final TestClass testClass = getTestClass(); final Description theDescription = Description.createTestDescription(testClass.getJavaClass(), aFrameworkMethod.getName() + " JVM Target"); aRunNotifier.fireTestStarted(theDescription); try { // Simply invoke using reflection final Object theInstance = testClass.getJavaClass().getDeclaredConstructor().newInstance(); final Method theMethod = aFrameworkMethod.getMethod(); theMethod.invoke(theInstance); aRunNotifier.fireTestFinished(theDescription); } catch (final Exception e) { aRunNotifier.fireTestFailure(new Failure(theDescription, e)); } } }
Example 2
Source File: LoadTimeWeavableTestRunner.java From rice with Educational Community License v2.0 | 6 votes |
protected boolean runBootstrapTest(RunNotifier notifier, TestClass testClass) { if (!runningBootstrapTest.get().booleanValue()) { runningBootstrapTest.set(Boolean.TRUE); try { BootstrapTest bootstrapTest = getBootstrapTestAnnotation(testClass.getJavaClass()); if (bootstrapTest != null) { Result result = JUnitCore.runClasses(bootstrapTest.value()); List<Failure> failures = result.getFailures(); for (Failure failure : failures) { notifier.fireTestFailure(failure); } return result.getFailureCount() == 0; } else { throw new IllegalStateException("LoadTimeWeavableTestRunner, must be coupled with an @BootstrapTest annotation to define the bootstrap test to execute."); } } finally { runningBootstrapTest.set(Boolean.FALSE); } } return true; }
Example 3
Source File: DirectoryRunner.java From EasyMPermission with MIT License | 6 votes |
@Override public void run(RunNotifier notifier) { if (failure != null) { notifier.fireTestStarted(description); notifier.fireTestFailure(new Failure(description, failure)); notifier.fireTestFinished(description); return; } for (Map.Entry<String, Description> entry : tests.entrySet()) { Description testDescription = entry.getValue(); notifier.fireTestStarted(testDescription); try { if (!runTest(entry.getKey())) { notifier.fireTestIgnored(testDescription); } } catch (Throwable t) { notifier.fireTestFailure(new Failure(testDescription, t)); } notifier.fireTestFinished(testDescription); } }
Example 4
Source File: StepNotificationHandler.java From zerocode with Apache License 2.0 | 6 votes |
Boolean handleAssertionFailed(RunNotifier notifier, Description description, String scenarioName, String stepName, List<FieldAssertionMatcher> failureReportList) { /** * Generate error report and display clearly which expectation(s) did not match */ LOGGER.error(String.format("Failed assertion during Scenario:%s, --> Step:%s, Details: %s\n", scenarioName, stepName, StringUtils.join(failureReportList, "\n"))); String prettyFailureMessage = String.format("Assertion failed for :- \n\n[%s] \n\t|\n\t|\n\t+---Step --> [%s] \n\nFailures:\n--------- %n%s%n", scenarioName, stepName, StringUtils.join(failureReportList, "\n" + deckedUpLine(maxEntryLengthOf(failureReportList)) + "\n")); LOGGER.error(prettyFailureMessage + "(See below 'Actual Vs Expected' to learn why this step failed) \n"); notifier.fireTestFailure(new Failure(description, new RuntimeException( prettyFailureMessage))); return false; }
Example 5
Source File: ZeroCodeMultiLoadRunner.java From zerocode with Apache License 2.0 | 6 votes |
@Override protected void runChild(TestMapping[] childArrayElement, RunNotifier notifier) { notifier.fireTestStarted(testDescription); Arrays.stream(childArrayElement).forEach(thisChild -> { loadProcessor.addTest(thisChild.testClass(), thisChild.testMethod()); }); boolean hasFailed = loadProcessor.processMultiLoad(); if (hasFailed) { String failureMessage = testClass.getName() + " with load/stress test(s): " + testDescription + " have Failed"; LOGGER.error(failureMessage + ". See target/logs -or- junit granular failure report(csv) -or- fuzzy search and filter report(html) for details"); notifier.fireTestFailure(new Failure(testDescription, new RuntimeException(failureMessage))); } notifier.fireTestFinished(testDescription); }
Example 6
Source File: AbstractMultiTestRunner.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void run(RunNotifier notifier) { Description description = getDescription(); notifier.fireTestStarted(description); notifier.fireTestFailure(new Failure(description, failure)); notifier.fireTestFinished(description); }
Example 7
Source File: SharedBehaviorTesting.java From FreeBuilder with Apache License 2.0 | 5 votes |
/** * Fails the {@link #introspection} test unless we managed to share a compiler. */ private void verifyCompilerShared(RunNotifier notifier, int numChildren, int numCompilations) { System.out.println(String.format( "Merged %d tests into %d compiler passes", numChildren, numCompilations)); int numFilteredChildren = superDescription.get().getChildren().size(); if (numFilteredChildren == numChildren) { if (numChildren == numCompilations) { notifier.fireTestFailure(new Failure( introspection, new AssertionError(MERGE_FAILURE_MESSAGE))); } } }
Example 8
Source File: SharedBehaviorTesting.java From FreeBuilder with Apache License 2.0 | 5 votes |
/** * Determines how many compilers we need and which children to pass them to. */ private Queue<SharedCompiler> getSharedCompilers(RunNotifier notifier) throws Throwable { notifier.fireTestStarted(introspection); try { List<Child> children = getChildMetadata(); Queue<SharedCompiler> sharedCompilers = shareCompilers(children); verifyCompilerShared(notifier, children.size(), sharedCompilers.size()); notifier.fireTestFinished(introspection); return sharedCompilers; } catch (Throwable t) { notifier.fireTestFailure(new Failure(introspection, t)); throw t; } }
Example 9
Source File: AbstractMultiTestRunner.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void run(RunNotifier notifier) { Description description = getDescription(); notifier.fireTestStarted(description); notifier.fireTestFailure(new Failure(description, failure)); notifier.fireTestFinished(description); }
Example 10
Source File: SafeRunner.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public void run(final RunNotifier notifier) { notifier.fireTestStarted(suiteDescription); try { delegate.run(notifier); } catch (Throwable e) { // NOSONAR Failure failure = new Failure(suiteDescription, e); notifier.fireTestFailure(failure); captureLogsOnFailure(failure); } finally { notifier.fireTestFinished(suiteDescription); } }
Example 11
Source File: ZeroCodeUnitRunner.java From zerocode with Apache License 2.0 | 5 votes |
private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno) { if (jsonTestCaseAnno != null) { currentTestCase = jsonTestCaseAnno.value(); } notifier.fireTestStarted(description); LOGGER.debug("### Running currentTestCase : " + currentTestCase); ScenarioSpec child = null; try { child = smartUtils.scenarioFileToJava(currentTestCase, ScenarioSpec.class); LOGGER.debug("### Found currentTestCase : -" + child); passed = multiStepsRunner.runScenario(child, notifier, description); } catch (Exception ioEx) { ioEx.printStackTrace(); notifier.fireTestFailure(new Failure(description, ioEx)); } testRunCompleted = true; if (passed) { LOGGER.info(String.format("\n**FINISHED executing all Steps for [%s] **.\nSteps were:%s", child.getScenarioName(), child.getSteps().stream() .map(step -> step.getName() == null ? step.getId() : step.getName()) .collect(Collectors.toList()))); } notifier.fireTestFinished(description); }
Example 12
Source File: AbstractSuiteRunner.java From lambda-behave with MIT License | 5 votes |
protected void reportResults(final RunNotifier notifier, final SpecificationReport spec, final Description test) { switch (spec.getResult()) { case SUCCESS: notifier.fireTestFinished(test); return; case FAILURE: notifier.fireTestFailure(new Failure(test, spec.getCause())); return; case ERROR: default: throw new SpecificationError(spec.getMessage(), spec.getCause()); } }
Example 13
Source File: MultipleBounceProxySetupsTestRunner.java From joynr with Apache License 2.0 | 5 votes |
@Override public void run(RunNotifier notifier) { for (SingleTestRunner testRunner : testRunners) { BounceProxyServerSetup bpConfig = testRunner.getSetup(); try { bpConfig.startServers(); testRunner.run(notifier); bpConfig.stopServers(); } catch (Exception e) { notifier.fireTestFailure(new Failure(testRunner.getDescription(), e)); } } }
Example 14
Source File: ScriptRunner.java From purplejs with Apache License 2.0 | 5 votes |
@Override public void run( final RunNotifier notifier ) { for ( final ScriptTestInstance file : this.testFiles ) { for ( final ScriptTestMethod method : file.getTestMethods() ) { final Description desc = Description.createTestDescription( file.getName(), method.getName() ); notifier.fireTestStarted( desc ); try { runBefore( file ); method.runTest( this.testInstance ); runAfter( file ); } catch ( final Throwable e ) { notifier.fireTestFailure( new Failure( desc, e ) ); } finally { notifier.fireTestFinished( desc ); } } file.dispose(); } }
Example 15
Source File: AbstractSuiteRunner.java From lambda-behave with MIT License | 5 votes |
@Override protected void runChild(final CompleteBehaviour child, final RunNotifier notifier) { try { Description childDescription = describeChild(child); notifier.fireTestStarted(childDescription); SpecificationReport report = child.playbackBehaviour(); reportResults(notifier, report, childDescription); } catch (final Exception e) { notifier.fireTestFailure(new Failure(getDescription(), e)); log.error(e.getMessage(), e); } }
Example 16
Source File: AbstractMultiTestRunner.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void run(RunNotifier notifier) { Description description = getDescription(); notifier.fireTestStarted(description); notifier.fireTestFailure(new Failure(description, failure)); notifier.fireTestFinished(description); }
Example 17
Source File: HashemTestRunner.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
@Override protected void runChild(TestCase testCase, RunNotifier notifier) { notifier.fireTestStarted(testCase.name); Context context = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); for (NodeFactory<? extends HashemBuiltinNode> builtin : builtins) { HashemLanguage.installBuiltin(builtin); } context = Context.newBuilder().in(new ByteArrayInputStream(testCase.testInput.getBytes("UTF-8"))).out(out).build(); PrintWriter printer = new PrintWriter(out); run(context, testCase.path, printer); printer.flush(); String actualOutput = new String(out.toByteArray()); Assert.assertEquals(testCase.name.toString(), testCase.expectedOutput, actualOutput); } catch (Throwable ex) { notifier.fireTestFailure(new Failure(testCase.name, ex)); } finally { if (context != null) { context.close(); } notifier.fireTestFinished(testCase.name); } }
Example 18
Source File: ArchTestExecution.java From ArchUnit with Apache License 2.0 | 4 votes |
@Override void notify(RunNotifier notifier) { notifier.fireTestFailure(new Failure(description, failure)); }
Example 19
Source File: BytecoderUnitTestRunner.java From Bytecoder with Apache License 2.0 | 4 votes |
private void testJSBackendFrameworkMethod(final FrameworkMethod aFrameworkMethod, final RunNotifier aRunNotifier, final TestOption aTestOption) { if ("".equals(System.getProperty("BYTECODER_DISABLE_JSTESTS", ""))) { final TestClass testClass = getTestClass(); final Description theDescription = Description.createTestDescription(testClass.getJavaClass(), aFrameworkMethod.getName() + " " + aTestOption.toDescription()); aRunNotifier.fireTestStarted(theDescription); try { final CompileTarget theCompileTarget = new CompileTarget(testClass.getJavaClass().getClassLoader(), CompileTarget.BackendType.js); final BytecodeMethodSignature theSignature = theCompileTarget.toMethodSignature(aFrameworkMethod.getMethod()); final BytecodeObjectTypeRef theTestClass = new BytecodeObjectTypeRef(testClass.getName()); final BytecodeMethodSignature theTestClassConstructorSignature = new BytecodeMethodSignature(BytecodePrimitiveTypeRef.VOID, new BytecodeTypeRef[0]); final StringWriter theStrWriter = new StringWriter(); final PrintWriter theCodeWriter = new PrintWriter(theStrWriter); final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, aTestOption.isExceptionsEnabled(), "bytecoder", 512, 512, aTestOption.isMinify(), aTestOption.isPreferStackifier(), Allocator.linear, additionalClassesToLink, additionalResources, null, aTestOption.isEscapeAnalysisEnabled()); final JSCompileResult result = (JSCompileResult) theCompileTarget.compile(theOptions, testClass.getJavaClass(), aFrameworkMethod.getName(), theSignature); final CompileResult.StringContent content = (CompileResult.StringContent) result.getContent()[0]; theCodeWriter.println(content.asString()); final String theFilename = result.getMinifier().toClassName(theTestClass) + "." + result.getMinifier().toMethodName(aFrameworkMethod.getName(), theSignature) + "_" + aTestOption.toFilePrefix() + ".html"; theCodeWriter.println(); theCodeWriter.println("console.log(\"Starting test\");"); theCodeWriter.println("bytecoder.bootstrap();"); theCodeWriter.println("var theTestInstance = " + result.getMinifier().toClassName(theTestClass) + "." + result.getMinifier().toSymbol("__runtimeclass") + "." + result.getMinifier().toMethodName("$newInstance", theTestClassConstructorSignature) + "();"); theCodeWriter.println("try {"); theCodeWriter.println(" theTestInstance." + result.getMinifier().toMethodName(aFrameworkMethod.getName(), theSignature) + "();"); theCodeWriter.println(" console.log(\"Test finished OK\");"); theCodeWriter.println("} catch (e) {"); theCodeWriter.println(" if (e.exception) {"); theCodeWriter.println(" console.log(\"Test finished with exception. Message = \" + bytecoder.toJSString(e.exception.message));"); theCodeWriter.println(" } else {"); theCodeWriter.println(" console.log(\"Test finished with exception.\");"); theCodeWriter.println(" }"); theCodeWriter.println(" console.log(e.stack);"); theCodeWriter.println("}"); theCodeWriter.flush(); final File theWorkingDirectory = new File("."); initializeTestWebServer(); final BrowserWebDriverContainer theContainer = initializeSeleniumContainer(); final File theMavenTargetDir = new File(theWorkingDirectory, "target"); final File theGeneratedFilesDir = new File(theMavenTargetDir, "bytecoderjs"); theGeneratedFilesDir.mkdirs(); // Copy additional resources for (final CompileResult.Content c : result.getContent()) { if (c instanceof CompileResult.URLContent) { try (final FileOutputStream fos = new FileOutputStream(new File(theGeneratedFilesDir, c.getFileName()))) { c.writeTo(fos); } } } final File theGeneratedFile = new File(theGeneratedFilesDir, theFilename); final PrintWriter theWriter = new PrintWriter(theGeneratedFile); theWriter.println("<html><body><script>"); theWriter.println(theStrWriter.toString()); theWriter.println("</script></body></html>"); theWriter.flush(); theWriter.close(); initializeWebRoot(theGeneratedFile.getParentFile()); final URL theTestURL = getTestFileUrl(theGeneratedFile); final WebDriver theDriver = theContainer.getWebDriver(); theDriver.get(theTestURL.toString()); final List<LogEntry> theAll = theDriver.manage().logs().get(LogType.BROWSER).getAll(); if (1 > theAll.size()) { aRunNotifier.fireTestFailure(new Failure(theDescription, new RuntimeException("No console output from browser"))); } for (final LogEntry theEntry : theAll) { LOGGER.info(theEntry.getMessage()); } final LogEntry theLast = theAll.get(theAll.size() - 1); if (!theLast.getMessage().contains("Test finished OK")) { aRunNotifier.fireTestFailure(new Failure(theDescription, new RuntimeException("Test did not succeed! Got : " + theLast.getMessage()))); } } catch (final Exception e) { aRunNotifier.fireTestFailure(new Failure(theDescription, e)); } finally { aRunNotifier.fireTestFinished(theDescription); } } }
Example 20
Source File: TestLoader.java From android-test with Apache License 2.0 | 4 votes |
@Override public void run(RunNotifier notifier) { notifier.fireTestStarted(description); notifier.fireTestFailure(failure); notifier.fireTestFinished(description); }