Java Code Examples for org.junit.runner.notification.RunNotifier#fireTestStarted()

The following examples show how to use org.junit.runner.notification.RunNotifier#fireTestStarted() . 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: TestRunner.java    From tutorials with MIT License 6 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    System.out.println("running the tests from MyRunner: " + testClass);
    try {
        Object testObject = testClass.newInstance();
        for (Method method : testClass.getMethods()) {
            if (method.isAnnotationPresent(Test.class)) {
                notifier.fireTestStarted(Description
                  .createTestDescription(testClass, method.getName()));
                method.invoke(testObject);
                notifier.fireTestFinished(Description
                  .createTestDescription(testClass, method.getName()));
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: DirectoryRunner.java    From EasyMPermission with MIT License 6 votes vote down vote up
@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 3
Source File: AbstractParallelScenarioRunner.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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());
			}
		}
	};
}
 
Example 4
Source File: ZeroCodePackageRunner.java    From zerocode with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = zeroCodeMultiStepsScenarioRunner.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);

}
 
Example 5
Source File: ZeroCodeMultiLoadRunner.java    From zerocode with Apache License 2.0 6 votes vote down vote up
@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: MyRunner.java    From new-bull with MIT License 6 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    System.out.println("running the tests from MyRunner. " + testClass);
    try {
        Object testObject = testClass.newInstance();
        for (Method method : testClass.getMethods()) {
            if (method.isAnnotationPresent(Test.class)) {
                notifier.fireTestStarted(Description.EMPTY);
                method.invoke(testObject);
                notifier.fireTestFinished(Description.EMPTY);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}
 
Example 7
Source File: AbstractMultiTestRunner.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
    }
}
 
Example 8
Source File: AbstractMultiTestRunner.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    Description description = getDescription();
    notifier.fireTestStarted(description);
    notifier.fireTestFailure(new Failure(description, failure));
    notifier.fireTestFinished(description);
}
 
Example 9
Source File: JavaScriptTestSuite.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
  notifier.fireTestStarted(description);
  try {
    testStatement.evaluate();
  } catch (Throwable throwable) {
    Failure failure = new Failure(description, throwable);
    notifier.fireTestFailure(failure);
  } finally {
    notifier.fireTestFinished(description);
  }
}
 
Example 10
Source File: AbstractMultiTestRunner.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    Description description = getDescription();
    notifier.fireTestStarted(description);
    notifier.fireTestFailure(new Failure(description, failure));
    notifier.fireTestFinished(description);
}
 
Example 11
Source File: ScriptRunner.java    From purplejs with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: SharedBehaviorTesting.java    From FreeBuilder with Apache License 2.0 5 votes vote down vote up
/**
 * 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 13
Source File: NonExecutingRunner.java    From android-test with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a list of tests to run by recursing over the {@link Description} hierarchy and firing
 * events to simulate the tests being run successfully.
 *
 * @param runNotifier the notifier to which the events are sent.
 * @param description the description to traverse.
 */
private void generateListOfTests(RunNotifier runNotifier, Description description) {
  List<Description> children = description.getChildren();
  if (children.isEmpty()) {
    runNotifier.fireTestStarted(description);
    runNotifier.fireTestFinished(description);
  } else {
    for (Description child : children) {
      generateListOfTests(runNotifier, child);
    }
  }
}
 
Example 14
Source File: ZeroCodeUnitRunner.java    From zerocode with Apache License 2.0 5 votes vote down vote up
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 15
Source File: AbstractMultiTestRunner.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    Description description = getDescription();
    notifier.fireTestStarted(description);
    notifier.fireTestFailure(new Failure(description, failure));
    notifier.fireTestFinished(description);
}
 
Example 16
Source File: SafeRunner.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@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 17
Source File: HashemTestRunner.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@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: TestBasedOnSampleRunner.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    notifier.fireTestStarted(getDescription());
    notifier.fireTestFinished(getDescription());
}
 
Example 19
Source File: BytecoderUnitTestRunner.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
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 vote down vote up
@Override
public void run(RunNotifier notifier) {
  notifier.fireTestStarted(description);
  notifier.fireTestFailure(failure);
  notifier.fireTestFinished(description);
}