org.junit.runners.Suite#org.junit.runner.Description源码实例Demo

下面列出了org.junit.runners.Suite#org.junit.runner.Description 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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.
        }
    };
}
 
源代码2 项目: n4js   文件: XpectCompareCommandHandler.java
@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;
}
 
@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);
        }
      }
    }
  };
}
 
源代码4 项目: activiti6-boot2   文件: ActivitiRule.java
/**
 * 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);
		}
	};
}
 
源代码5 项目: Selenium-Foundation   文件: TargetPlatformRule.java
@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);
            }
        };
    }
}
 
源代码6 项目: spring-cloud-contract   文件: StubRunnerRule.java
@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();
		}
	};
}
 
源代码7 项目: attic-apex-malhar   文件: JsonFormatterTest.java
@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);
}
 
源代码8 项目: flink   文件: ExternalResource.java
@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();
		}
	};
}
 
源代码9 项目: kripton   文件: JunitTaskExecutorRule.java
@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();
			}
		}
	};
}
 
源代码10 项目: joynr   文件: IltConsumerJUnitListener.java
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");
}
 
源代码11 项目: usergrid   文件: NoAWSCredsRule.java
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 );


            }
        }
    };
}
 
源代码12 项目: activiti6-boot2   文件: ActivitiDmnRule.java
private void skippedQuietly(AssumptionViolatedException e, Description description, List<Throwable> errors) {
    try {
        skipped(e, description);
    } catch (Throwable t) {
        errors.add(t);
    }
}
 
源代码13 项目: openCypher   文件: ParameterTest.java
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() );
}
 
源代码14 项目: pushfish-android   文件: JUnitTestEventAdapter.java
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");
    }
}
 
源代码15 项目: astor   文件: JUnitFailureHackerTest.java
@Test
public void shouldPrintTheWarningSoICanSeeIt() throws Exception {
    Failure failure = new Failure(Description.EMPTY, new RuntimeException("foo"));
    
    //when
    hacker.appendWarnings(failure, "unused stubbing blah");
    
    //then
    System.out.println(failure.getException());        
}
 
源代码16 项目: logging-log4j2   文件: ThreadedTest.java
@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();
            }
        }
    };
}
 
源代码17 项目: flowable-engine   文件: FlowableCmmnRule.java
private void succeededQuietly(Description description, List<Throwable> errors) {
    try {
        succeeded(description);
    } catch (Throwable t) {
        errors.add(t);
    }
}
 
源代码18 项目: android-test   文件: BundleJUnitUtilsTest.java
@Test
public void fromFailure() {
  Class<SampleJUnitTest> testClass = SampleJUnitTest.class;
  Description jUnitDescription = Description.createTestDescription(testClass, "sampleTest");
  Throwable throwable = new RuntimeException("Your test is bad and you should feel bad.");
  Failure jUnitFailure = new Failure(jUnitDescription, throwable);

  ParcelableFailure parcelableFailure =
      BundleJUnitUtils.getFailure(
          parcelBundle(BundleJUnitUtils.getBundleFromFailure(jUnitFailure)));

  assertThat(parcelableFailure.getTrace(), is(jUnitFailure.getTrace()));
  compareDescription(parcelableFailure.getDescription(), jUnitFailure.getDescription());
}
 
源代码19 项目: joynr   文件: IltConsumerJUnitListener.java
@Override
public void testAssumptionFailure(Failure failure) {
    logger.info(">>> testAssumptionFailure called");
    Description description = failure.getDescription();
    printDescription(description, 1);
    // should have been created already in previous call to testStarted
    TestSuiteResultsStore store = getStore(description);
    store.errors++;
    logger.info("<<< testAssumptionFailure called");
}
 
源代码20 项目: j2objc   文件: JUnitTestRunner.java
@Override
public void testStarted(Description description) throws Exception {
  numTests++;
  testFailure = null;
  testStartTime = System.currentTimeMillis();
  printf("Test Case '-[%s]' started.\n", parseDescription(description));
}
 
源代码21 项目: spliceengine   文件: OuterJoinIT.java
@Override
protected void starting(Description description) {
    try {
        insertData(cc.toString(), dd.toString(), spliceClassWatcher);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        spliceClassWatcher.closeAll();
    }
}
 
源代码22 项目: botsing   文件: CarvingRunListener.java
@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());
    }

}
 
源代码23 项目: Pushjet-Android   文件: AbstractMultiTestRunner.java
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);
}
 
源代码24 项目: java-sdk   文件: LogbackVerifier.java
@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();
            }
        }
    };
}
 
源代码25 项目: pitest   文件: RunnerSuiteFinder.java
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();
    }
  };
}
 
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);
    }
}
 
@Override
public TestRule applyTo(final JenkinsInstance jenkins) {
    return new TestWatcher() {
        @Override protected void starting(Description description) {

            warmUpUpdateCenterCacheFor(jenkins);

            jenkins.client().installPlugins(requiredPlugins);
        }
    };
}
 
源代码28 项目: examples   文件: RuleWithArqResAndCDIInStatement.java
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();
            }
        };
    }
 
源代码29 项目: scheduling   文件: RepeatRule.java
@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;
}
 
源代码30 项目: bazel   文件: ShardingFilterTestCase.java
/**
 * 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);
}