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

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

源代码1 项目: n4js   文件: N4IDEXpectFileNameUtil.java
/***/
public static String getTestName(Description description) {
	String text = null;
	if (description.isTest()) {
		String s = description.getDisplayName();

		if (s.startsWith(TEST_FILE_INIT_ERROR_MSG)) {
			return TEST_FILE_INIT_ERROR_MSG;
		}

		// seems like malformed xt file - no XPECT comment ?
		if (s.indexOf("#") < 0 || s.indexOf("~") < 0) {
			return s;
		}

		int posXT = s.indexOf("#");
		int posTM = s.indexOf("~", posXT);
		text = s.substring(posXT + 1, posTM);
	}
	return text;
}
 
源代码2 项目: bazel   文件: RoundRobinShardingFilter.java
/**
 * Given a list of test case descriptions, returns a mapping from each
 * to its index in the list.
 */
private static Map<Description, Integer> buildTestToShardMap(
    Collection<Description> testDescriptions) {
  Map<Description, Integer> map = new HashMap<>();

  // Sorting this list is incredibly important to correctness. Otherwise,
  // "shuffled" suites would break the sharding protocol.
  List<Description> sortedDescriptions = new ArrayList<>(testDescriptions);
  Collections.sort(sortedDescriptions, new DescriptionComparator());

  // If we get two descriptions that are equal, the shard number for the second
  // one will overwrite the shard number for the first.  Thus they'll run on the
  // same shard.
  int index = 0;
  for (Description description : sortedDescriptions) {
    if (!description.isTest()) {
      throw new IllegalArgumentException("Test suite should not be included in the set of tests "
          + "to shard: " + description.getDisplayName());
    }
    map.put(description, index);
    index++;
  }
  return Collections.unmodifiableMap(map);
}
 
源代码3 项目: n4js   文件: XpectLabelProvider.java
@Override
public String getText(Object element) {

	if (element instanceof Description == false) {
		return "";
	}

	Description desc = ((Description) element);

	if (desc.isSuite()) {
		return N4IDEXpectFileNameUtil.getSuiteName(desc);
	}

	if (desc.isTest()) {
		return N4IDEXpectFileNameUtil.getTestName(desc);
	}

	return "";
}
 
源代码4 项目: n4js   文件: XpectLabelProvider.java
/**
 * get icon based on item type (test/suite) and its status (pass/failed/exception/skip/in progress...)
 */
private ImageDescriptor getImageDescriptor(Object element) throws RuntimeException {
	ImageDescriptor descriptor = null;
	if (element instanceof Description == false) {
		String msg = "Unknown type of element in tree of type " + element.getClass().getName();
		Exception e = new RuntimeException(msg);
		N4IDEXpectUIPlugin.logError("cannot obtain image descriptor, fallback to default", e);
		return getImageDescriptor("n4_logo.png");
	}

	Description desc = (Description) element;

	if (desc.isTest()) {
		descriptor = getTestImageDescriptor(executionStatus.getStatus(desc));
	} else if (desc.isSuite()) {
		descriptor = getSuiteImageDescriptor(desc, executionStatus.getStatus(desc));
	} else {
		descriptor = getImageDescriptor("n4_logo.png");
	}
	return descriptor;
}
 
源代码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);
            }
        };
    }
}
 
@Override
public Statement apply(final Statement base, final Description description) {

	return new Statement() {

		@Override
		public void evaluate() throws Throwable {

			if (description.isTest()) {
				if (RequiresRedisSentinel.this.requiredSentinels != null) {
					verify(RequiresRedisSentinel.this.requiredSentinels);
				}

			} else {
				verify(RequiresRedisSentinel.this.requiredSentinels);
			}

			base.evaluate();
		}
	};
}
 
源代码7 项目: junit-dataprovider   文件: DataProviderFilter.java
@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;
}
 
源代码8 项目: android-test   文件: ParentFilter.java
/** {@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;
}
 
源代码9 项目: marathonv5   文件: AllureMarathonRunListener.java
public void startFakeTestCase(Description description) {
    String uid = getSuiteUid(description);

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

    fireClearStepStorage();
    getLifecycle().fire(event);
}
 
源代码10 项目: public   文件: JUnitGradeSheetListener.java
@Override
public void testStarted(final Description description) {
    if (description.isTest() && isGradable(description)) {
        currentTest = currentSuiteTests.get(description);
    } else {
        currentTest = null;
    }
}
 
源代码11 项目: public   文件: JUnitGradeSheetListener.java
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;
}
 
源代码12 项目: public   文件: JUnitGradeSheetListener.java
@Override
public void testStarted(final Description description) {
    if (description.isTest() && isGradable(description)) {
        currentProblems = new ArrayList<>();
    } else {
        currentProblems = null;
    }
}
 
源代码13 项目: public   文件: JUnitGradeSheetListener.java
@Override
public void testStarted(final Description description) {
    if (description.isTest() && isGradable(description)) {
        currentTest = currentSuiteTests.get(description);
    } else {
        currentTest = null;
    }
}
 
源代码14 项目: bazel   文件: DynamicTestException.java
/**
 * Constructs a {@code DynamicTestFailureException} that indicates a
 * dynamically-discovered test, specified as a (@link Description}, failed
 * due to the specified {@code cause}.
 */
public DynamicTestException(Description test, Throwable cause) {
  super(cause);
  if (!test.isTest()) {
    throw new IllegalArgumentException();
  }
  this.test = test;
}
 
/**
 * Validates the annotation of the rule field in the test class.
 * 
 * @param description
 */
private void validateRuleAnnotations(Description description) {

    // If the first run is a @ClassRule run, check if @Rule is annotated
    if (firstRun && !description.isTest()) {

        /*
         * Get the fields of the test class and check if there is only one
         * coverage rule and if the coverage rule field is annotation with
         * both @ClassRule and @Rule.
         */

        int numberOfCoverageRules = 0;
        for (Field field : description.getTestClass().getFields()) {

            final Class<?> fieldType = field.getType();
            if (getClass().isAssignableFrom(fieldType)) {

                ++numberOfCoverageRules;

                final boolean isClassRule = field.isAnnotationPresent(ClassRule.class);
                final boolean isRule = field.isAnnotationPresent(Rule.class);
                if (isClassRule && !isRule) {

                    throw new RuntimeException(getClass().getCanonicalName()
                            + " can only be used as a @ClassRule if it is also a @Rule!");
                }
            }
        }

        // TODO if they really want to have multiple runs, let them?
        if (numberOfCoverageRules > 1) {
            throw new RuntimeException("Only one coverage rule can be used per test class!");
        }
    }
}
 
源代码16 项目: android-test   文件: TestRequestBuilder.java
@Override
public boolean shouldRun(Description description) {
  if (description.isTest()) {
    return (Math.abs(description.hashCode()) % numShards) == shardIndex;
  }

  // The description is a suite, so assume that it can be run so that filtering is
  // applied to its children. If after filtering it has no children then it will be
  // automatically filtered out.
  return true;
}
 
源代码17 项目: allure-cucumberjvm   文件: AllureRunListener.java
public void startFakeTestCase(Description description) throws IllegalAccessException {
    String uid = getSuiteUid(description);

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

    getLifecycle().fire(event);
}
 
源代码18 项目: bazel   文件: TestSuiteModel.java
private void addTestCase(TestSuiteNode parentSuite, Description testCaseDesc) {
  if (!testCaseDesc.isTest()) {
    throw new IllegalArgumentException();
  }
  if (!shardingFilter.shouldRun(testCaseDesc)) {
    return;
  }
  TestCaseNode testCase = new TestCaseNode(testCaseDesc, parentSuite);
  testsMap.put(testCaseDesc, testCase);
  parentSuite.addTestCase(testCase);
}
 
public void addTests(Description description) {
  if (description.isEmpty()) {
    return;
  }

  if (description.isTest()) {
    addTest(description.getClassName() + "#" + description.getMethodName());
  } else {
    for (Description child : description.getChildren()) {
      addTests(child);
    }
  }
}
 
/**
 * If the rule is a @ClassRule log and assert the coverage and create a
 * graphical report. For the class coverage to work all the test method
 * deployments have to be equal.
 * 
 * @param description
 */
private void handleClassCoverage(Description description) {

    // If the rule is a class rule get the class coverage
    if (!description.isTest()) {

        final ClassCoverage classCoverage = coverageTestRunState.getClassCoverage();

        // Make sure the class coverage deals with the same deployments for
        // every test method
        classCoverage.assertAllDeploymentsEqual();

        final double classCoveragePercentage = classCoverage.getCoveragePercentage();

        // Log coverage percentage
        logger.info(
                coverageTestRunState.getTestClassName() + " test class coverage is: " + classCoveragePercentage);

        logCoverageDetail(classCoverage);

        // Create graphical report
        CoverageReportUtil.createClassReport(processEngine, coverageTestRunState);

        assertCoverage(classCoveragePercentage, classCoverageAssertionMatchers);

    }
}