@Test public void failsUnused() { Result result = TestRunner.runTest(FailsUnused.class); assertThat(result.wasSuccessful()).isFalse(); List<Failure> failures = result.getFailures(); assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1); Failure failure = failures.get(0); assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class) .hasMessage(FailsUnused.message); assertThat(FailsUnused.count).isEqualTo(1); }
public Result execute() { Preconditions.checkState( isStarted.get(), "Cannot execute a tracker that has not started!" ); Result result = new JUnitCore().run( testClass ); long runTime = result.getRunTime(); // collect some statistics maxTime = Math.max( maxTime, runTime ); minTime = Math.min( minTime, runTime ); long timesRun = actualIterations.incrementAndGet(); long totalTime = totalRunTime.addAndGet( runTime ); totalTestsRun.addAndGet( result.getRunCount() ); meanTime = totalTime / timesRun; if ( ! result.wasSuccessful() ) { failures.addAndGet( result.getFailureCount() ); ignores.addAndGet( result.getIgnoreCount() ); } resultsLog.write( result ); return result; }
public Result result() { Result result = new Result(); RunListener listener = result.createListener(); for (Failure failure : failures) { try { listener.testFailure(failure); } catch (Exception e) { throw new RuntimeException("I can't believe this happened"); } } return result; } }
@Override public void testRunFinished(Result result) { if (result != null) { System.out.println("testRunFinished " + String.valueOf(result) + " time:" + String.valueOf(result.getRunTime()) + " R" + String.valueOf(result.getRunCount()) + " F" + String.valueOf(result.getFailureCount()) + " I" + String.valueOf(result.getIgnoreCount()) ); } }
protected void printFooter(Result result) { if (result.wasSuccessful()) { getWriter().println(); getWriter().print("OK"); getWriter().println(" (" + result.getRunCount() + " test" + (result.getRunCount() == 1 ? "" : "s") + ")"); } else { getWriter().println(); getWriter().println("FAILURES!!!"); getWriter().println("Tests run: " + result.getRunCount() + ", Failures: " + result.getFailureCount()); } getWriter().println(); }
@Test public void shouldOnlyCallBeforeAfterSuiteOnce() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); Result result = run(adaptor, ClassWithArquillianClassAndMethodRule.class, ClassWithArquillianClassAndMethodRule.class, ClassWithArquillianClassAndMethodRule.class, ClassWithArquillianClassAndMethodRule.class); Assert.assertTrue(result.wasSuccessful()); verify(adaptor, times(4)).beforeSuite(); verify(adaptor, times(4)).afterSuite(); }
@Test public void shouldWorkWithTimeout() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); Result result = run(adaptor, ClassWithArquillianRunnerWithTimeout.class); Assert.assertFalse(result.wasSuccessful()); Assert.assertTrue(result.getFailures().get(0).getMessage().contains("timed out")); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.BEFORE, Cycle.AFTER, Cycle.AFTER_CLASS); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldCallAllMethodsWithRealAdapter() throws Exception { System.setProperty("arquillian.debug", "true"); TestRunnerAdaptor adaptor = spy(TestRunnerAdaptorBuilder.build()); Result result = run(adaptor, ArquillianClass1.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.values()); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); } }
@Test public void should_not_execute_class_rule() throws Exception { // given TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); // when Result result = run(adaptor, ClassWithArquillianRunnerWithRules.class); // then Assert.assertTrue(result.wasSuccessful()); Assert.assertEquals(0, result.getFailureCount()); Assert.assertEquals(0, result.getIgnoreCount()); assertCycle(1, Cycle.BEFORE_RULE, Cycle.BEFORE_CLASS, Cycle.BEFORE, Cycle.TEST, Cycle.AFTER, Cycle.AFTER_CLASS, Cycle.AFTER_RULE); assertCycle(0, Cycle.BEFORE_CLASS_RULE, Cycle.AFTER_CLASS_RULE); } }
private void testTimeout(Class<?> testClass) { Result result = run(testClass); assertEquals(1, result.getRunCount()); assertEquals(1, result.getFailureCount()); Failure failure = result.getFailures().get(0); assertTrue("Was expecting failure " + failure.getException() + " to be instance of " + TimeoutException.class, failure.getException() instanceof TimeoutException); }
public static Result runTestWithValidation(final Class<?> test) { JUnitCore junitCore = new JUnitCore(); Result result = junitCore.run(Request.aClass(test).getRunner()); List<Failure> failures = result.getFailures(); if (!failures.isEmpty()) { Failure firstFailure = failures.get(0); throw new AssertionError(firstFailure.getException()); } assertThat(result.wasSuccessful()).isTrue(); return result; }
@Test public void testReportLateFailures() { Result result; try { result = new JUnitCore().run(new BlockJUnit4ClassRunner(LateFailureReport.class)); } catch (InitializationError initializationError) { throw new AssertionError(initializationError); } assertEquals(1, result.getFailureCount()); assertEquals(IllegalStateException.class, result.getFailures().get(0).getException().getClass()); } }
public static void main(String[] args) { try { H2O.main(args); TestUtil.stall_till_cloudsize(3); List<Class> tests = JUnitRunner.all(); Result r = org.junit.runner.JUnitCore.runClasses(tests.toArray(new Class[0])); if( r.getFailureCount() == 0 ) { System.out.println("Successfully ran the following tests in " + (r.getRunTime() / 1000) + "s"); for( Class c : tests ) System.out.println(c.getName()); } else { for( Failure f : r.getFailures() ) { System.err.println(f.getDescription()); if( f.getException() != null ) f.getException().printStackTrace(); } } System.exit(r.getFailureCount()); } catch( Throwable t ) { t.printStackTrace(); System.exit(1); } } }
/** * @param system * @args args from main() */ private Result runMain(JUnitSystem system, String... args) { system.out().println("JUnit version " + Version.id()); List<Class<?>> classes = new ArrayList<Class<?>>(); List<Failure> missingClasses = new ArrayList<Failure>(); for (String each : args) { try { classes.add(Class.forName(each)); } catch (ClassNotFoundException e) { system.out().println("Could not find class: " + each); Description description = Description.createSuiteDescription(each); Failure failure = new Failure(description, e); missingClasses.add(failure); } } RunListener listener = new TextListener(system); addListener(listener); Result result = run(classes.toArray(new Class[0])); for (Failure each : missingClasses) { result.getFailures().add(each); } return result; }
public static Failure runTestWithExpectedFailure(final Class<?> test) { JUnitCore junitCore = new JUnitCore(); Result result = junitCore.run(Request.aClass(test).getRunner()); List<Failure> failures = result.getFailures(); assertThat(failures).hasSize(1); return failures.get(0); }
@Override protected int doWork() throws Exception { //this is called from the command line, so we should set to use the distributed cluster IntegrationTestingUtility.setUseDistributedCluster(conf); Class<?>[] classes = findIntegrationTestClasses(); LOG.info("Found " + classes.length + " integration tests to run:"); for (Class<?> aClass : classes) { LOG.info(" " + aClass); } JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); Result result = junit.run(classes); return result.wasSuccessful() ? 0 : 1; } }
public TestResult(Result result) { runCount = result.getRunCount(); failureCount = result.getFailureCount(); ignoreCount = result.getIgnoreCount(); runTime = result.getRunTime(); if (!wasSuccessful()) { throwable = result.getFailures().get(0).getException(); } }
@Test public void testBrokenCategoryAndParameterized() { Request request = Request.aClass(BrokenCategoryClass.class); ExposedParameterized runner = (ExposedParameterized) request.getRunner(); request = request.filterWith(new CategoryFilter( (ExposedBlockJUnit4ClassRunnerWithParameters) runner.getChildren().get(0))); Result result = new JUnitCore().run(request); assertEquals( "Yeah!! This might actually mean we've upgraded to JUnit 4.13. Hurry up already and delete this hack.", 1, result.getRunCount()); }
/** * Prints an information about result of the test running. * * @param out output stream * @param result the summary of the test run, including all the tests that failed */ public static void testRunFinished(PrintStream out, Result result) { out.printf( "Total tests run: %d, Failures: %d, Skips: %d", result.getRunCount(), result.getFailureCount(), result.getIgnoreCount()); }
public ResultDTO(Result result) { this.successful = result.wasSuccessful(); this.ignoreCount = result.getIgnoreCount(); this.failureCount = result.getFailureCount(); this.runCount = result.getRunCount(); this.runTime = result.getRunTime(); List<Failure> failureList = result.getFailures(); for (Failure failure : failureList) { failures.add(new FailureDTO(failure)); } }