createTestDescription()源码实例Demo

org.junit.runner.Description#createTestDescription()源码实例Demo

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

源代码1 项目: android-test   文件: SuiteAssignmentPrinterTest.java
@Test
public void methodIsAssignedToWrongSuite_sendSuiteSuggestion() throws Exception {
  Description description =
      Description.createTestDescription(
          SampleTestClassWithSizeAnnotations.class,
          "mediumSizeTest",
          SampleTestClassWithSizeAnnotations.class.getMethod("mediumSizeTest").getAnnotations());

  // Don't output anything in instrumentation status
  doNothing().when(suiteAssignmentPrinter).sendStatus(anyInt(), any(Bundle.class));
  // Set end time
  when(suiteAssignmentPrinter.getCurrentTimeMillis()).thenReturn(100L);

  // Set time for small test bucket
  suiteAssignmentPrinter.timingValid = true;
  suiteAssignmentPrinter.startTime = 50L;
  suiteAssignmentPrinter.testFinished(description);

  verify(suiteAssignmentPrinter).sendString(contains("suggested: small"));
}
 
源代码2 项目: purplejs   文件: ScriptRunner.java
@Override
public Description getDescription()
{
    final Description suite = Description.createSuiteDescription( this.testClass );
    for ( final ScriptTestInstance file : this.testFiles )
    {
        final Description desc = Description.createTestDescription( file.getName(), file.getName() );
        suite.addChild( desc );

        for ( final ScriptTestMethod method : file.getTestMethods() )
        {
            final Description methodDesc = Description.createTestDescription( file.getName(), method.getName() );
            desc.addChild( methodDesc );
        }
    }

    return suite;
}
 
源代码3 项目: bazel   文件: JUnit4RunnerTest.java
@Test
public void testFilteringAndShardingTogetherIsSupported() {
  config = createConfig("testThatAlways(Passes|Fails)");
  shardingEnvironment = mock(ShardingEnvironment.class);
  shardingFilters = new FakeShardingFilters(
      Description.createTestDescription(SamplePassingTest.class, "testThatAlwaysPasses"),
      Description.createTestDescription(SampleFailingTest.class, "testThatAlwaysFails"));

  when(shardingEnvironment.isShardingEnabled()).thenReturn(true);

  JUnit4Runner runner = createRunner(SampleSuite.class);
  Result result = runner.run();

  verify(shardingEnvironment).touchShardFile();

  assertThat(result.getRunCount()).isEqualTo(2);
  assertThat(result.getFailureCount()).isEqualTo(1);
  assertThat(result.getIgnoreCount()).isEqualTo(0);
  assertThat(result.getFailures().get(0).getDescription())
      .isEqualTo(
          Description.createTestDescription(SampleFailingTest.class, "testThatAlwaysFails"));
}
 
源代码4 项目: bazel   文件: JUnit4RunnerTest.java
@Test
public void testPassingTest() throws Exception {
  config = createConfig();
  mockRunListener = mock(RunListener.class);

  JUnit4Runner runner = createRunner(SamplePassingTest.class);

  Description testDescription =
      Description.createTestDescription(SamplePassingTest.class, "testThatAlwaysPasses");
  Description suiteDescription =
      Description.createSuiteDescription(SamplePassingTest.class);
  suiteDescription.addChild(testDescription);

  Result result = runner.run();

  assertThat(result.getRunCount()).isEqualTo(1);
  assertThat(result.getFailureCount()).isEqualTo(0);
  assertThat(result.getIgnoreCount()).isEqualTo(0);

  assertPassingTestHasExpectedOutput(stdoutByteStream, SamplePassingTest.class);

  InOrder inOrder = inOrder(mockRunListener);

  inOrder.verify(mockRunListener).testRunStarted(suiteDescription);
  inOrder.verify(mockRunListener).testStarted(testDescription);
  inOrder.verify(mockRunListener).testFinished(testDescription);
  inOrder.verify(mockRunListener).testRunFinished(any(Result.class));
}
 
源代码5 项目: android-test   文件: TestsRegExFilterTest.java
@Test
public void partialClassName() {
  TestsRegExFilter filter = new TestsRegExFilter();
  filter.setPattern("TestFixture");
  Description d = Description.createTestDescription(TestFixture.class, "any");

  assertThat(filter.evaluateTest(d)).isTrue();
}
 
/**
 * A simple test to ensure expected output is generated for test run with a single passed test.
 */
@Test
public void testSinglePass() {
  Description testDescription = Description.createTestDescription(CLASS_NAME, TEST_NAME, 1);
  resultReporter.orchestrationRunStarted(1);
  runTestSucceed(testDescription, true);
  resultReporter.orchestrationRunFinished();
  String output = getOutput();
  // TODO: consider doing xml based compare
  assertTrue(output.contains("tests=\"1\" failures=\"0\" errors=\"0\""));
  final String testCaseTag =
      String.format("<testcase name=\"%s\" classname=\"%s\"", TEST_NAME, CLASS_NAME);
  assertTrue(output.contains(testCaseTag));
}
 
源代码7 项目: android-test   文件: SuiteAssignmentPrinterTest.java
@Test
public void timingInvalid_sendsFailure() throws Exception {
  Description description =
      Description.createTestDescription(
          SampleTestClassWithSizeAnnotations.class, "smallSizeTest");

  doNothing().when(suiteAssignmentPrinter).sendStatus(anyInt(), any(Bundle.class));
  suiteAssignmentPrinter.timingValid = false;
  suiteAssignmentPrinter.testFinished(description);

  verify(suiteAssignmentPrinter).sendString(eq("F"));
}
 
源代码8 项目: EasyMPermission   文件: DirectoryRunner.java
private void addTests(Class<?> testClass) throws Exception {
	for (File file : params.getBeforeDirectory().listFiles(JAVA_FILE_FILTER)) {
		if (!params.accept(file)) continue;
		Description testDescription = Description.createTestDescription(testClass, file.getName());
		description.addChild(testDescription);
		tests.put(file.getName(), testDescription);
	}
}
 
源代码9 项目: buck   文件: EndToEndRunner.java
/**
 * Needed for ParentRunner implementation, describeChild creates a testDescription from the
 * testMethod and the name we get from the test descriptor built off of environment configuration.
 */
@Override
protected Description describeChild(EndToEndTestDescriptor child) {
  if (setupError != null) {
    return Description.createTestDescription(getTestClass().getJavaClass(), child.getName());
  }
  return Description.createTestDescription(
      getTestClass().getJavaClass(), child.getName(), child.getMethod().getAnnotations());
}
 
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  listener = new OrchestratedInstrumentationListener(this);
  listener.odoCallback = mockCallback;

  Class<SampleJUnitTest> testClass = SampleJUnitTest.class;
  jUnitDescription = Description.createTestDescription(testClass, "sampleTest");
  jUnitFailure = new Failure(jUnitDescription, new Throwable("error"));
  jUnitResult = new Result();
  RunListener jUnitListener = jUnitResult.createListener();
  jUnitListener.testRunStarted(jUnitDescription);
  jUnitListener.testStarted(jUnitDescription);
  jUnitListener.testFinished(jUnitDescription);
}
 
源代码11 项目: android-test   文件: TestSizeTest.java
@Test
public void classNotAnnotatedWithTestSize_ReturnsTrue() {
  Description testClassRunnerFilterSmallSizeTestDescription =
      Description.createTestDescription(
          SampleTestRunnerFilterSizeAnnotatedClass.class, "testMethod");
  assertThat(
      testSize.testClassIsAnnotatedWithTestSize(testClassRunnerFilterSmallSizeTestDescription),
      equalTo(true));

  Description testClassPlatformSmallSizeTestDescription =
      Description.createTestDescription(SampleTestPlatformSizeAnnotatedClass.class, "testMethod");
  assertThat(
      testSize.testClassIsAnnotatedWithTestSize(testClassPlatformSmallSizeTestDescription),
      equalTo(true));
}
 
源代码12 项目: video-recorder-java   文件: TestUtils.java
public static void runRule(TestRule rule, Object target, String methodName) {
    Class<?> clazz = target.getClass();
    Method method = TestUtils.getMethod(clazz, methodName);
    Description description = Description.createTestDescription(clazz, method.getName(), method.getDeclaredAnnotations());
    try {
        InvokeMethod invokeMethod = new InvokeMethod(new FrameworkMethod(method), target);
        rule.apply(invokeMethod, description).evaluate();
    } catch (Throwable throwable) {
        logger.warning(Arrays.toString(throwable.getStackTrace()));
    }
}
 
源代码13 项目: codenjoy   文件: SmartAssert.java
private Description description(Method method) {
    return Description.createTestDescription(test, method.getName());
}
 
源代码14 项目: rice   文件: LoadTimeWeavableTestRunner.java
protected Description describeOriginalChild(FrameworkMethod method) {
    return Description.createTestDescription(getOriginalTestClass().getJavaClass(),
            testName(method), method.getAnnotations());
}
 
源代码15 项目: tutorials   文件: TestRunner.java
@Override
public Description getDescription() {
    return Description.createTestDescription(testClass, "My runner description");
}
 
源代码16 项目: testcontainers-java   文件: FlakyRuleTest.java
private Description newDescriptionWithAnnotationAndCustomTries(int maxTries) {
    return Description.createTestDescription("SomeTestClass", "someMethod", newAnnotation(VALID_DATE_IN_FAR_FUTURE, VALID_URL, maxTries));
}
 
源代码17 项目: rice   文件: LoadTimeWeavableTestRunner.java
/**
 * Returns a {@link org.junit.runner.Description} for {@code child}, which can be assumed to
 * be an element of the list returned by {@link #getChildren()}
 */
protected Description describeChild(FrameworkMethod method) {
    return Description.createTestDescription(getTestClass().getJavaClass(),
            testName(method), method.getAnnotations());
}
 
源代码18 项目: codenjoy   文件: SmartAssert.java
@Override
public Description getDescription() {
    return Description.createTestDescription(test, 
            "Do not panic! You have performed wonders in this... colourful Universe.");
}
 
源代码19 项目: joynr   文件: SingleTestRunner.java
@Override
protected Description describeChild(FrameworkMethod method) {
    return Description.createTestDescription(getTestClass().getJavaClass().getName(),
                                             testName(method),
                                             testName(method) + "-" + bounceProxySetup.getClass().getSimpleName());
}
 
源代码20 项目: ArchUnit   文件: ArchTestMethodExecution.java
@Override
Description describeSelf() {
    return Description.createTestDescription(testClass, testMethod.getName());
}