org.junit.runner.Description Java Examples

The following examples show how to use org.junit.runner.Description. 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: JsonFormatterTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
protected void starting(Description descriptor)
{
  super.starting(descriptor);
  deleteDirectory();

  operator = new JsonFormatter();

  validDataSink = new CollectorTestSink<Object>();
  invalidDataSink = new CollectorTestSink<String>();
  TestUtils.setSink(operator.out, validDataSink);
  TestUtils.setSink(operator.err, invalidDataSink);
  operator.setup(null);

  operator.beginWindow(0);
}
 
Example #2
Source File: ActivitiRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			List<Throwable> errors = new ArrayList<Throwable>();

			startingQuietly(description, errors);
			try {
				base.evaluate();
				succeededQuietly(description, errors);
			} catch (AssumptionViolatedException e) {
				errors.add(e);
				skippedQuietly(e, description, errors);
			} catch (Throwable t) {
				errors.add(t);
				failedQuietly(t, description, errors);
			} finally {
				finishedQuietly(description, errors);
			}

			MultipleFailureException.assertEmpty(errors);
		}
	};
}
 
Example #3
Source File: RevertDefaultThreadHandlerRule.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(Statement s, Description d) {
  return new StatementAdapter(s) {
    @Override
    protected void before() throws Throwable {
      if (!applied.getAndSet(true)) {
        UncaughtExceptionHandler p = Thread.getDefaultUncaughtExceptionHandler();
        try {
          // Try to initialize a zookeeper class that reinitializes default exception handler.
          Class<?> cl = NIOServerCnxnFactory.class;
          // Make sure static initializers have been called.
          Class.forName(cl.getName(), true, cl.getClassLoader());
        } finally {
          if (p == Thread.getDefaultUncaughtExceptionHandler()) {
          //  throw new RuntimeException("Zookeeper no longer resets default thread handler.");
          }
          Thread.setDefaultUncaughtExceptionHandler(p);
        }
      }
    }
  };
}
 
Example #4
Source File: IltConsumerJUnitListener.java    From joynr with Apache License 2.0 6 votes vote down vote up
public void testIgnored(Description description) {
    logger.info(">>> testIgnored called");
    printDescription(description, 1);
    if (description == null || description.getDisplayName() == null) {
        logger.info("<<< testFinished called");
        return;
    }

    TestSuiteResultsStore store = getStore(description);
    // create new entry
    TestCaseResult testCaseResult = new TestCaseResult(getTestCaseName(description),
                                                       getTestSuiteClassName(description),
                                                       //new Long(endTimeTestCase - startTimeTestCase).toString(),
                                                       "0.000",
                                                       "ignored", // status
                                                       null, // no failure
                                                       null // no systemOut
    );
    store.testCaseResults.add(testCaseResult);
    store.skipped++;

    logger.info("<<< testIgnored called");
}
 
Example #5
Source File: JunitTaskExecutorRule.java    From kripton with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			beforeStart();
			try {
				base.evaluate();
				finishExecutors();
			} catch (Throwable t) {
				throw new RuntimeException(t);
			} finally {
				afterFinished();
			}
		}
	};
}
 
Example #6
Source File: TargetPlatformRule.java    From Selenium-Foundation with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    if (!description.isTest()) return base;

    final String contextPlatform = SeleniumConfig.getConfig().getContextPlatform();
    final TargetPlatform targetPlatform = description.getAnnotation(TargetPlatform.class);
    
    platform = TargetPlatformHandler.resolveTargetPlatform(testObject, targetPlatform);
    
    if (TargetPlatformHandler.shouldRun(contextPlatform, platform)) {
        return base;
    } else {
        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                String message = String.format("%s.%s() doesn't specify platform '%s'",
                        description.getClassName(), description.getMethodName(), contextPlatform);
                throw new AssumptionViolatedException(message);
            }
        };
    }
}
 
Example #7
Source File: StubRunnerRule.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			before();
			base.evaluate();
			StubRunnerRule.this.stubFinder().close();
		}

		private void before() {
			stubFinder(new BatchStubRunnerFactory(builder().build(), verifier())
					.buildBatchStubRunner());
			StubRunnerRule.this.stubFinder().runStubs();
		}
	};
}
 
Example #8
Source File: ExternalResource.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
default Statement apply(final Statement base, final Description description) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			before();
			try {
				base.evaluate();
			} catch (final Throwable testThrowable) {
				try {
					afterTestFailure();
				} catch (final Throwable afterFailureThrowable) {
					testThrowable.addSuppressed(afterFailureThrowable);
				}
				throw testThrowable;
			}
			afterTestSuccess();
		}
	};
}
 
Example #9
Source File: NoAWSCredsRule.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public Statement apply( final Statement base, final Description description ) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {

            try {
                base.evaluate();
            }
            catch ( Throwable t ) {

                if ( !isMissingCredsException( t ) ) {
                    throw t;
                }

                //do this so our test gets marked as ignored.  Not pretty, but it works
                Assume.assumeTrue( false );


            }
        }
    };
}
 
Example #10
Source File: XpectCompareCommandHandler.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

	IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);

	IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
	try {
		view = (N4IDEXpectView) windows[0].getActivePage().showView(
				N4IDEXpectView.ID);
	} catch (PartInitException e) {
		N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
	}

	Description desc = (Description) selection.getFirstElement();
	if (desc.isTest() && view.testsExecutionStatus.hasFailed(desc)) {
		Throwable failureException = view.testsExecutionStatus.getFailure(desc).getException();

		if (failureException instanceof ComparisonFailure) {
			ComparisonFailure cf = (ComparisonFailure) failureException;
			// display comparison view
			displayComparisonView(cf, desc);
		}
	}
	return null;
}
 
Example #11
Source File: ActivityRule.java    From AndroidEspressoIdlingResourcePlayground with MIT License 6 votes vote down vote up
@Override
public final Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            launchActivity();

            base.evaluate();

            if(!activity.isFinishing()) {
                activity.finish();
            }
            activity = null; // Eager reference kill in case someone leaked our reference.
        }
    };
}
 
Example #12
Source File: OuterJoinIT.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void starting(Description description) {
    try {
        insertData(cc.toString(), dd.toString(), spliceClassWatcher);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        spliceClassWatcher.closeAll();
    }
}
 
Example #13
Source File: RunnerSuiteFinder.java    From pitest with Apache License 2.0 5 votes vote down vote up
private static Function<Description, Stream<Class<?>>> descriptionToTestClass() {
  return a -> {
    final Class<?> clazz = a.getTestClass();
    if (clazz != null) {
      return Stream.of(clazz);
    } else {
      return Stream.empty();
    }
  };
}
 
Example #14
Source File: LastIndexKeyOperationIT.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void starting(Description description) {
    PreparedStatement ps;
    try {
        ps = spliceClassWatcher.prepareStatement(
                String.format("insert into %s (i) values (?)", spliceTableWatcher));
        for(int i=1;i<MAX+1;i++){
            ps.setInt(1,i);
            ps.addBatch();
        }
        ps.executeBatch();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #15
Source File: CarvingRunListener.java    From botsing with Apache License 2.0 5 votes vote down vote up
@Override
public void testFinished(Description description) {
    try {
        final CaptureLog log = Capturer.stopCapture();
        LOG.trace("Carving test {}.{}", description.getClassName(), description.getMethodName());
        List<Class<?>> observedClasses = this.processLog(description, log);
        for(Class<?> clazz : observedClasses) {
            TestUsagePoolManager.getInstance().addTest(clazz.getName(), description.getClassName());
        }
        Capturer.clear();
    } catch(Exception e) {
        LOG.warn("Error in capturing log of class {}.",description.getClassName());
    }

}
 
Example #16
Source File: JUnitTestEventAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private TestDescriptorInternal nullSafeDescriptor(Object id, Description description) {
    if (methodName(description) != null) {
        return new DefaultTestDescriptor(id, className(description), methodName(description));
    } else {
        return new DefaultTestDescriptor(id, className(description), "classMethod");
    }
}
 
Example #17
Source File: AbstractMultiTestRunner.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void testStarted(Description description) {
    Description translated = translateDescription(description);
    notifier.fireTestStarted(translated);
    if (!started && !complete) {
        try {
            assertCanExecute();
            started = true;
            before();
        } catch (Throwable t) {
            notifier.fireTestFailure(new Failure(translated, t));
        }
    }
}
 
Example #18
Source File: ParameterTest.java    From openCypher with Apache License 2.0 5 votes vote down vote up
private Single( Class<?> testClass, FrameworkMethod method ) throws Throwable
{
    super( testClass );
    this.method = method;
    this.parameter = method.invokeExplosively( null );
    this.description = Description.createTestDescription(
            testClass, method.getName(), method.getAnnotations() );
}
 
Example #19
Source File: Suite.java    From spectrum with MIT License 5 votes vote down vote up
private void runSuite(final RunReporting<Description, Failure> reporting) {
  if (isEffectivelyIgnored()) {
    runChildren(reporting);
  } else {
    this.hooks.once().sorted()
        .runAround(this.description, reporting, () -> runChildren(reporting));
  }
}
 
Example #20
Source File: ThreadedTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            deleteDir();
            try {
                base.evaluate();
            } finally {
                deleteDir();
            }
        }
    };
}
 
Example #21
Source File: AbstractMultiTestRunner.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void runEnabledTests(RunNotifier nested) {
    if (enabledTests.isEmpty()) {
        return;
    }

    Runner runner;
    try {
        runner = createExecutionRunner();
    } catch (Throwable t) {
        runner = new CannotExecuteRunner(getDisplayName(), target, t);
    }

    try {
        if (!disabledTests.isEmpty()) {
            ((Filterable) runner).filter(new Filter() {
                @Override
                public boolean shouldRun(Description description) {
                    return !disabledTests.contains(description);
                }

                @Override
                public String describe() {
                    return "disabled tests";
                }
            });
        }
    } catch (NoTestsRemainException e) {
        return;
    }

    runner.run(nested);
}
 
Example #22
Source File: LogbackVerifier.java    From java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            before();
            try {
                base.evaluate();
                verify();
            } finally {
                after();
            }
        }
    };
}
 
Example #23
Source File: ManagedTimeUnifiedStateImplTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
protected void starting(Description description)
{
  TestUtils.deleteTargetTestClassFolder(description);
  managedState = new ManagedTimeUnifiedStateImpl();
  applicationPath = "target/" + description.getClassName() + "/" + description.getMethodName();
  ((FileAccessFSImpl)managedState.getFileAccess()).setBasePath(applicationPath + "/" + "bucket_data");

  operatorContext = ManagedStateTestUtils.getOperatorContext(9, applicationPath);
}
 
Example #24
Source File: IgnoredTestDescriptorProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
List<Description> getAllDescriptions(Description description, String className) {
    final AllExceptIgnoredTestRunnerBuilder allExceptIgnoredTestRunnerBuilder = new AllExceptIgnoredTestRunnerBuilder();
    try {
        final Class<?> testClass = description.getClass().getClassLoader().loadClass(className);
        Runner runner = allExceptIgnoredTestRunnerBuilder.runnerForClass(testClass);
        if (runner == null) {
            //fall back to default runner
            runner = Request.aClass(testClass).getRunner();
        }
        final Description runnerDescription = runner.getDescription();
        return runnerDescription.getChildren();
    } catch (Throwable throwable) {
        throw new TestSuiteExecutionException(String.format("Unable to process Ignored class %s.", className), throwable);
    }
}
 
Example #25
Source File: AllureRunListener.java    From allure1 with Apache License 2.0 5 votes vote down vote up
public void startFakeTestCase(Description description) {
    String uid = getSuiteUid(description);

    String name = description.isTest() ? description.getMethodName() : description.getClassName();
    TestCaseStartedEvent event = new TestCaseStartedEvent(uid, name);
    AnnotationManager am = new AnnotationManager(description.getAnnotations());
    am.update(event);

    fireClearStepStorage();
    getLifecycle().fire(event);
}
 
Example #26
Source File: InstallPluginsFromUpdateCenter.java    From jenkins-build-monitor-plugin with MIT License 5 votes vote down vote up
@Override
public TestRule applyTo(final JenkinsInstance jenkins) {
    return new TestWatcher() {
        @Override protected void starting(Description description) {

            warmUpUpdateCenterCacheFor(jenkins);

            jenkins.client().installPlugins(requiredPlugins);
        }
    };
}
 
Example #27
Source File: TestRuleAssertionsRequired.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      try {
        // Make sure -ea matches -Dtests.asserts, to catch accidental mis-use:
        if (LuceneTestCase.assertsAreEnabled != LuceneTestCase.TEST_ASSERTS_ENABLED) {
          String msg = "Assertions mismatch: ";
          if (LuceneTestCase.assertsAreEnabled) {
            msg += "-ea was specified";
          } else {
            msg += "-ea was not specified";
          }
          if (LuceneTestCase.TEST_ASSERTS_ENABLED) {
            msg += " but -Dtests.asserts=true";
          } else  {
            msg += " but -Dtests.asserts=false";
          }
          System.err.println(msg);
          throw new Exception(msg);
        }
      } catch (AssertionError e) {
        // Ok, enabled.
      }

      base.evaluate();
    }
  };
}
 
Example #28
Source File: RuleWithArqResAndCDIInStatement.java    From examples with Apache License 2.0 5 votes vote down vote up
public Statement apply(final Statement base, final Description description) {

        return new Statement() {
            @Override public void evaluate() throws Throwable {
                Assert.assertNotNull(bean);
                Assert.assertNotNull(url);
                Assert.assertThat(url.toString(), CoreMatchers.containsString(AbstractTestCase.DEPLOYMENT_NAME));

                base.evaluate();
            }
        };
    }
 
Example #29
Source File: RepeatRule.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Statement apply(Statement statement, Description description) {
    Statement result = statement;
    Repeat repeat = description.getAnnotation(Repeat.class);
    if (repeat != null) {
        int times = repeat.value();
        boolean parallel = repeat.parallel();
        long timeout = repeat.timeout();
        result = new RepeatStatement(times, parallel, timeout, statement);
    }
    return result;
}
 
Example #30
Source File: ShardingFilterTestCase.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the sharding is complete (each test is run at least once) and
 * partitioned (each test is run at most once) -- in other words, that
 * each test is run exactly once.  This is a requirement of all test
 * sharding functions.
 */
protected static void assertShardingIsCompleteAndPartitioned(List<Filter> filters,
    List<Description> descriptions) {
  Map<Filter, List<Description>> run = simulateTestRun(filters, descriptions);
  assertThatCollectionContainsExactlyElementsInList(getAllValuesInMap(run), descriptions);

  run = simulateSelfRandomizingTestRun(filters, descriptions);
  assertThatCollectionContainsExactlyElementsInList(getAllValuesInMap(run), descriptions);
}