Java Code Examples for org.junit.runner.Description#getChildren()
The following examples show how to use
org.junit.runner.Description#getChildren() .
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: AbstractGremlinSuite.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public boolean shouldRun(final Description description) { // first check if all tests from a class should be ignored - where "OptOut.method" is set to "*". the // description appears to be null in some cases of parameterized tests, but if the entire test case // was ignored it would have been caught earlier and these parameterized tests wouldn't be considered // for a call to shouldRun if (description.getTestClass() != null) { final boolean ignoreWholeTestCase = entireTestCaseToIgnore.stream().map(this::transformToClass) .anyMatch(claxx -> claxx.isAssignableFrom(description.getTestClass())); if (ignoreWholeTestCase) return false; } if (description.isTest()) { // next check if there is a test group to consider. if not then check for a specific test to ignore return !(!testGroupToIgnore.isEmpty() && testGroupToIgnore.stream().anyMatch(optOut -> optOut.getTestClass().isAssignableFrom(description.getTestClass()) && description.getMethodName().equals(optOut.getMethodName()))) && !individualSpecificTestsToIgnore.contains(description); } // explicitly check if any children want to run for (Description each : description.getChildren()) { if (shouldRun(each)) { return true; } } return false; }
Example 2
Source File: IltConsumerJUnitListener.java From joynr with Apache License 2.0 | 6 votes |
public void printDescription(Description description, int level) { String spaces = new String(new char[level * 2]).replace('\0', ' '); if (description == null) { logger.info(spaces + "description is null"); } else { logger.info(spaces + "description is set"); logger.info(spaces + "- description.getDisplayName() = " + description.toString()); logger.info(spaces + "- description.isEmpty() = " + description.isEmpty()); logger.info(spaces + "- description.isSuite() = " + description.isSuite()); logger.info(spaces + "- description.isTest() = " + description.isTest()); logger.info(spaces + "- description.testCount() = " + description.testCount()); ArrayList<Description> children = description.getChildren(); for (int i = 0; i < children.size(); i++) { printDescription(children.get(i), level + 1); } logger.info(spaces + "- description.toString() = " + description.toString()); } }
Example 3
Source File: IltConsumerJUnitListener.java From joynr with Apache License 2.0 | 6 votes |
public void printDescription(Description description, int level) { String spaces = new String(new char[level * 2]).replace('\0', ' '); if (description == null) { logger.info(spaces + "description is null"); } else { logger.info(spaces + "description is set"); logger.info(spaces + "- description.getDisplayName() = " + description.toString()); logger.info(spaces + "- description.isEmpty() = " + description.isEmpty()); logger.info(spaces + "- description.isSuite() = " + description.isSuite()); logger.info(spaces + "- description.isTest() = " + description.isTest()); logger.info(spaces + "- description.testCount() = " + description.testCount()); ArrayList<Description> children = description.getChildren(); for (int i = 0; i < children.size(); i++) { printDescription(children.get(i), level + 1); } logger.info(spaces + "- description.toString() = " + description.toString()); } }
Example 4
Source File: AbstractMultiTestRunner.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
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: DataProviderFilter.java From junit-dataprovider with Apache License 2.0 | 6 votes |
@Override public boolean shouldRun(Description description) { String filterDescription = filter.describe(); Matcher filterDescriptionMatcher = DESCRIPTION_PATTERN.matcher(filterDescription); if (filterDescription.contains(" OR ") || !filterDescriptionMatcher.find()) { return filter.shouldRun(description); } String methodName = filterDescriptionMatcher.group(GROUP_METHOD_NAME); String className = filterDescriptionMatcher.group(GROUP_CLASS); if (description.isTest()) { return shouldRunTest(description, filterDescriptionMatcher, methodName, className); } // explicitly check if any children should to run for (Description each : description.getChildren()) { if (shouldRun(each)) { return true; } } return false; }
Example 6
Source File: JUnitGradeSheetListener.java From public with Apache License 2.0 | 5 votes |
private GradingSuite parseSuite(final Description description) { final GradedCategory annotation = description.getAnnotation(GradedCategory.class); final String suiteName = annotation.name().equals(GradedTest.DEFAULT_NAME) ? description.getDisplayName() : annotation.name(); final String suiteDescription = annotation.description().equals(GradedTest.DEFAULT_DESCRIPTION) ? null : annotation.description(); final String suiteGroup = annotation.group().equals(GradedCategory.DEFAULT_GROUP) ? null : annotation.group(); final GradingSuite suite = new GradingSuite(description.getClassName(), suiteName, suiteDescription, suiteGroup, annotation.pointsFormat()); for (final Description child : description.getChildren()) { if (isGradable(child)) { if (child.isTest()) { suite.tests.add(parseTest(child, annotation.pointsFormat())); } else { throw new AssertionError("Non-test child. How did you even do that?"); } } } return suite; }
Example 7
Source File: NonExecutingRunner.java From android-test with Apache License 2.0 | 5 votes |
/** * Generates a list of tests to run by recursing over the {@link Description} hierarchy and firing * events to simulate the tests being run successfully. * * @param runNotifier the notifier to which the events are sent. * @param description the description to traverse. */ private void generateListOfTests(RunNotifier runNotifier, Description description) { List<Description> children = description.getChildren(); if (children.isEmpty()) { runNotifier.fireTestStarted(description); runNotifier.fireTestFinished(description); } else { for (Description child : children) { generateListOfTests(runNotifier, child); } } }
Example 8
Source File: EclipseParameterized.java From tddl5 with Apache License 2.0 | 5 votes |
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: IgnoredTestDescriptorProvider.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
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 10
Source File: IgnoredTestDescriptorProvider.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
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 11
Source File: TestSuiteModel.java From bazel with Apache License 2.0 | 5 votes |
private void addTestSuite(TestSuiteNode parentSuite, Description suiteDescription) { TestSuiteNode suite = new TestSuiteNode(suiteDescription); for (Description childDesc : suiteDescription.getChildren()) { if (childDesc.isTest()) { addTestCase(suite, childDesc); } else { addTestSuite(suite, childDesc); } } // Empty suites are pruned when sharding. if (shardingFilter == Filter.ALL || !suite.getChildren().isEmpty()) { parentSuite.addTestSuite(suite); testsMap.put(suiteDescription, suite); } }
Example 12
Source File: FilterRegistry.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Check recursively if at least one child description should be run. * * @param description * the parent {@link Description}, must not be {@code null} * @return whether there are runnable children */ private boolean hasRunnableChildren(final Description description) { for (final Description child : description.getChildren()) { if (shouldRun(child)) { return true; } } return false; }
Example 13
Source File: HybrisJUnitIntegrationTestLoader.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 5 votes |
private Description getRootDescription(Runner runner, DescriptionMatcher matcher) { Description current= runner.getDescription(); while (true) { List<Description> children= current.getChildren(); if (children.size() != 1 || matcher.matches(current)) return current; current= children.get(0); } }
Example 14
Source File: ParameterisedJUnitTestFinder.java From pitest with Apache License 2.0 | 5 votes |
private List<TestUnit> handleParameterizedTest(final Class<?> clazz, final Description description) { final List<TestUnit> result = new ArrayList<>(); for (final Description each : description.getChildren()) { FCollection.mapTo(each.getChildren(), parameterizedToTestUnit(clazz), result); } return result; }
Example 15
Source File: NeodymiumTest.java From neodymium-library with MIT License | 5 votes |
public void checkDescription(Description testDescription, String[] expectedTestDescription) { ArrayList<Description> testChildren = testDescription.getChildren(); String[] actualDescription = new String[testChildren.size()]; for (int i = 0; i < testChildren.size(); i++) { actualDescription[i] = testChildren.get(i).getMethodName(); } Arrays.sort(actualDescription); Arrays.sort(expectedTestDescription); Assert.assertArrayEquals(expectedTestDescription, actualDescription); }
Example 16
Source File: EclipseParameterized.java From tddl with Apache License 2.0 | 5 votes |
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 17
Source File: ParentFilter.java From android-test with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public boolean shouldRun(Description description) { if (description.isTest()) { return evaluateTest(description); } // this is a suite, explicitly check if any children should run for (Description each : description.getChildren()) { if (shouldRun(each)) { return true; } } // no children to run, filter this out return false; }
Example 18
Source File: IgnoredTestDescriptorProvider.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
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 19
Source File: TestSuiteModel.java From bazel with Apache License 2.0 | 5 votes |
private void markChildrenAsPending(Description node) { if (node.isTest()) { testPending(node); } else { for (Description child : node.getChildren()) { markChildrenAsPending(child); } } }
Example 20
Source File: NeodymiumRunner.java From neodymium-library with MIT License | 4 votes |
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; }