Java Code Examples for org.junit.runner.Description#addChild()

The following examples show how to use org.junit.runner.Description#addChild() . 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: BddScenariosCounterTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCounterIgnoresDescriptionsWithMethodNames() throws Exception
{
    Description root = Description.createSuiteDescription(ROOT);
    Description beforeStories = Description.createTestDescription(Object.class, BEFORE);
    Description story = Description.createSuiteDescription(STORY);
    Description beforeStory = Description.createTestDescription(Object.class, BEFORE);
    Description scenario = Description.createSuiteDescription(SCENARIO);

    root.addChild(beforeStories);
    root.addChild(story);
    story.addChild(beforeStory);
    story.addChild(scenario);

    Properties properties = mockPropertiesBeanInstantiation();
    mockJUnitReportingRunnerInstantiation(root);

    BddScenariosCounter.main(new String[0]);

    verify(properties).put(RESOURCE_LOCATION, DEFAULT_STORY_LOCATION);
    assertThat(getOutStreamContent(), containsString(1 + SEPARATOR + STORIES));
    assertThat(getOutStreamContent(), containsString(1 + SEPARATOR + SCENARIOS));
    assertThat(getOutStreamContent(), containsString(1 + SEPARATOR + SCENARIOS_WITH_EXAMPLES));
}
 
Example 2
Source File: AbstractMultiTestRunner.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void map(Description source, Description parent) {
    for (Description child : source.getChildren()) {
        Description mappedChild;
        if (child.getMethodName() != null) {
            mappedChild = Description.createSuiteDescription(String.format("%s [%s](%s)", child.getMethodName(), getDisplayName(), child.getClassName()));
            parent.addChild(mappedChild);
            if (!isTestEnabled(new TestDescriptionBackedTestDetails(source, child))) {
                disabledTests.add(child);
            } else {
                enabledTests.add(child);
            }
        } else {
            mappedChild = Description.createSuiteDescription(child.getClassName());
        }
        descriptionTranslations.put(child, mappedChild);
        map(child, parent);
    }
}
 
Example 3
Source File: JUnit38ClassRunner.java    From android-test with Apache License 2.0 6 votes vote down vote up
static Description makeDescription(Test test) {
  if (test instanceof TestCase) {
    TestCase tc = (TestCase) test;
    return Description.createTestDescription(tc.getClass(), tc.getName(), getAnnotations(tc));
  } else if (test instanceof TestSuite) {
    TestSuite ts = (TestSuite) test;
    String name = ts.getName() == null ? createSuiteDescription(ts) : ts.getName();
    Description description = Description.createSuiteDescription(name);
    int n = ts.testCount();
    for (int i = 0; i < n; i++) {
      Description made = makeDescription(ts.testAt(i));
      description.addChild(made);
    }
    return description;
  } else if (test instanceof Describable) {
    Describable adapter = (Describable) test;
    return adapter.getDescription();
  } else if (test instanceof TestDecorator) {
    TestDecorator decorator = (TestDecorator) test;
    return makeDescription(decorator.getTest());
  } else {
    // This is the best we can do in this case
    return Description.createSuiteDescription(test.getClass());
  }
}
 
Example 4
Source File: AbstractMultiTestRunner.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void map(Description source, Description parent) {
    for (Description child : source.getChildren()) {
        Description mappedChild;
        if (child.getMethodName() != null) {
            mappedChild = Description.createSuiteDescription(String.format("%s [%s](%s)", child.getMethodName(), getDisplayName(), child.getClassName()));
            parent.addChild(mappedChild);
            if (!isTestEnabled(new TestDescriptionBackedTestDetails(source, child))) {
                disabledTests.add(child);
            } else {
                enabledTests.add(child);
            }
        } else {
            mappedChild = Description.createSuiteDescription(child.getClassName());
        }
        descriptionTranslations.put(child, mappedChild);
        map(child, parent);
    }
}
 
Example 5
Source File: AbstractMultiTestRunner.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void map(Description source, Description parent) {
    for (Description child : source.getChildren()) {
        Description mappedChild;
        if (child.getMethodName() != null) {
            mappedChild = Description.createSuiteDescription(String.format("%s [%s](%s)", child.getMethodName(), getDisplayName(), child.getClassName()));
            parent.addChild(mappedChild);
            if (!isTestEnabled(new TestDescriptionBackedTestDetails(source, child))) {
                disabledTests.add(child);
            } else {
                enabledTests.add(child);
            }
        } else {
            mappedChild = Description.createSuiteDescription(child.getClassName());
        }
        descriptionTranslations.put(child, mappedChild);
        map(child, parent);
    }
}
 
Example 6
Source File: ScriptRunner.java    From purplejs with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 7
Source File: PinpointPluginTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public Description getDescription() {
    Description description = Description.createSuiteDescription(getName(), getRunnerAnnotations());
    for (FrameworkMethod child : getFilteredChildren()) {
        description.addChild(describeChild(child));
    }
    return description;
}
 
Example 8
Source File: EclipseParameterized.java    From tddl with Apache License 2.0 5 votes vote down vote up
private static Description wrap(Description description) {
    String name = description.getDisplayName();
    String fixedName = deparametrizedName(name);
    Description clonedDescription = Description.createSuiteDescription(fixedName, description.getAnnotations()
        .toArray(new Annotation[0]));
    for (Description child : description.getChildren()) {
        clonedDescription.addChild(wrap(child));
    }
    return clonedDescription;
}
 
Example 9
Source File: PtlBlockJUnit4ClassRunnerWithParameters.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
/**
 * 実行されるテストのdescriptionを取得します。
 * 
 * @return description
 */
public Description getTestDescription() {
	Description description = getDescription();
	Description result = Description.createTestDescription(getTestClass().getJavaClass(), getName(),
			getRunnerAnnotations());
	for (Description d : description.getChildren()) {
		result.addChild(d);
	}
	return result;
}
 
Example 10
Source File: JUnit4RunnerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailingInternationalCharsTest() throws Exception {
  config = createConfig();
  mockRunListener = mock(RunListener.class);

  JUnit4Runner runner = createRunner(SampleInternationalFailingTest.class);

  Description testDescription = Description.createTestDescription(
      SampleInternationalFailingTest.class, "testFailingInternationalCharsTest");
  Description suiteDescription = Description.createSuiteDescription(
      SampleInternationalFailingTest.class);
  suiteDescription.addChild(testDescription);

  Result result = runner.run();

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

  String output = new String(stdoutByteStream.toByteArray(), StandardCharsets.UTF_8);
  // Intentionally swapped "Test 日\u672C." / "Test \u65E5本." to make sure that the "raw"
  // character does not get corrupted (would become ? in both cases and we would not notice).
  assertThat(output).contains("expected:<Test [Japan].> but was:<Test [日\u672C].>");

  InOrder inOrder = inOrder(mockRunListener);

  inOrder.verify(mockRunListener).testRunStarted(any(Description.class));
  inOrder.verify(mockRunListener).testStarted(any(Description.class));
  inOrder.verify(mockRunListener).testFailure(any(Failure.class));
  inOrder.verify(mockRunListener).testFinished(any(Description.class));
  inOrder.verify(mockRunListener).testRunFinished(any(Result.class));
}
 
Example 11
Source File: JTAFMasterSuite.java    From JTAF-XCore with Apache License 2.0 5 votes vote down vote up
@Override
public Description getDescription() {
	Description description = Description.createSuiteDescription("Automated Tests");
	for (Runner child : getChildren()) {
		description.addChild(describeChild(child));
	}
	return description;
}
 
Example 12
Source File: GTestRunner.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Description getDescription() {
	Description description = Description.createSuiteDescription(testClass);
	for (Entry<String, List<String>> entry : testCases.entrySet()) {
		for (String test : entry.getValue()) {
			String testCase = entry.getKey();
			Description childDescription = createDescription(testCase, test);
			description.addChild(childDescription);
		}
	}
	return description;
}
 
Example 13
Source File: ComplianceRunner.java    From jmespath-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Description getDescription() {
  Description description = Description.createSuiteDescription(testClass.getName(), testClass.getAnnotations());
  for (JmesPathComplianceTest.ComplianceTest<T> complianceTest : getAllTests()) {
    description.addChild(createDescription(complianceTest));
  }
  return description;
}
 
Example 14
Source File: NeodymiumRunner.java    From neodymium-library with MIT License 5 votes vote down vote up
private Description createFlatTestDescription(List<FrameworkMethod> methods)
{
    Description flatDescription = Description.createSuiteDescription(getTestClass().getJavaClass());

    for (FrameworkMethod method : methods)
    {
        flatDescription.addChild(describeChild(method));
    }

    return flatDescription;
}
 
Example 15
Source File: PinpointPluginTestSuite.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public Description getDescription() {
    Description description = Description.createSuiteDescription(getName(), getRunnerAnnotations());
    for (Runner child : getFilteredChildren()) {
        description.addChild(describeChild(child));
    }
    return description;
}
 
Example 16
Source File: JustTestLahRunner.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
@Override
public Description getDescription() {
  if (properties.getProperty(CLOUD_PROVIDER, CLOUDPROVIDER_LOCAL).equals(CLOUDPROVIDER_AWS)) {
    Description suiteDescription =
        Description.createSuiteDescription(AWS_JUNIT_SUITE_DESCRIPTION);
    suiteDescription.addChild(
        Description.createTestDescription("groupName", AWS_JUNIT_GROUP_DESCRIPTION));
    return suiteDescription;
  } else {
    return super.getDescription();
  }
}
 
Example 17
Source File: RunUntilFailure.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private Description describeRepeatTest(FrameworkMethod method) {  
    int times = method.getAnnotation(Repeat.class).value();  

    Description description = Description.createSuiteDescription(  
            testName(method) + " [" + times + " times]",  
            method.getAnnotations());  

    for (int i = 1; i <= times; i++) {  
        description.addChild(Description.createTestDescription(  
                getTestClass().getJavaClass(),  
                testName(method) + "-" + i));  
    }  
    return description;  
}
 
Example 18
Source File: JUnit4RunnerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailingTest() throws Exception {
  config = createConfig();
  mockRunListener = mock(RunListener.class);

  JUnit4Runner runner = createRunner(SampleFailingTest.class);

  Description testDescription = Description.createTestDescription(SampleFailingTest.class,
      "testThatAlwaysFails");
  Description suiteDescription = Description.createSuiteDescription(SampleFailingTest.class);
  suiteDescription.addChild(testDescription);

  Result result = runner.run();

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

  assertThat(extractOutput(stdoutByteStream))
      .contains(
          "1) testThatAlwaysFails("
              + SampleFailingTest.class.getName()
              + ")\n"
              + "java.lang.AssertionError: expected");

  InOrder inOrder = inOrder(mockRunListener);

  inOrder.verify(mockRunListener).testRunStarted(any(Description.class));
  inOrder.verify(mockRunListener).testStarted(any(Description.class));
  inOrder.verify(mockRunListener).testFailure(any(Failure.class));
  inOrder.verify(mockRunListener).testFinished(any(Description.class));
  inOrder.verify(mockRunListener).testRunFinished(any(Result.class));
}
 
Example 19
Source File: NeodymiumRunner.java    From neodymium-library with MIT License 4 votes vote down vote up
private Description createHierarchicalTestDescription(List<FrameworkMethod> methods)
{
    Description hierarchicalDescription = Description.createSuiteDescription(getTestClass().getJavaClass());

    for (FrameworkMethod method : methods)
    {
        Description currentLevel = hierarchicalDescription;
        if (method instanceof EnhancedMethod)
        {
            EnhancedMethod enhancedMethod = (EnhancedMethod) method;
            List<StatementBuilder> statementBuilder = enhancedMethod.getBuilder();
            List<Object> builderData = enhancedMethod.getData();

            for (int i = 0; i < statementBuilder.size(); i++)
            {
                StatementBuilder builder = statementBuilder.get(i);
                String categoryName = builder.getCategoryName(builderData.get(i));

                // check if hierarchical description has a child with that description
                ArrayList<Description> currentLevelChildren = currentLevel.getChildren();
                boolean found = false;
                for (Description currentLevelChild : currentLevelChildren)
                {
                    if (categoryName.equals(currentLevelChild.getDisplayName()))
                    {
                        found = true;
                        currentLevel = currentLevelChild;
                        break;
                    }
                }

                // create one if it's missing and set the new one as the current level, then dig deeper
                if (!found)
                {
                    Description newChild = Description.createSuiteDescription(categoryName);
                    currentLevel.addChild(newChild);
                    currentLevel = newChild;
                }

            }
            // finally add the test method to lowest level
            currentLevel.addChild(describeChild(method));
        }
        else
        {
            // it's just a default JUnit method, just add it as child
            hierarchicalDescription.addChild(describeChild(method));
        }
    }

    return hierarchicalDescription;
}
 
Example 20
Source File: ShardingFilterTestCase.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a test suite description (a Description that returns true
 * when {@link org.junit.runner.Description#isSuite()} is called.)
 */
protected static Description createTestSuiteDescription() {
  Description testSuiteDescription = Description.createSuiteDescription("testSuite");
  testSuiteDescription.addChild(Description.createSuiteDescription("testCase"));
  return testSuiteDescription;
}