Java Code Examples for org.junit.runner.Description#isTest()
The following examples show how to use
org.junit.runner.Description#isTest() .
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: N4IDEXpectFileNameUtil.java From n4js with Eclipse Public License 1.0 | 6 votes |
/***/ 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; }
Example 2
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 3
Source File: RequiresRedisSentinel.java From spring-data-examples with Apache License 2.0 | 6 votes |
@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(); } }; }
Example 4
Source File: TargetPlatformRule.java From Selenium-Foundation with Apache License 2.0 | 6 votes |
@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); } }; } }
Example 5
Source File: XpectLabelProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * 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; }
Example 6
Source File: XpectLabelProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
@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 ""; }
Example 7
Source File: RoundRobinShardingFilter.java From bazel with Apache License 2.0 | 6 votes |
/** * 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); }
Example 8
Source File: AllureMarathonRunListener.java From marathonv5 with Apache License 2.0 | 5 votes |
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); }
Example 9
Source File: JUnitGradeSheetListener.java From public with Apache License 2.0 | 5 votes |
@Override public void testStarted(final Description description) { if (description.isTest() && isGradable(description)) { currentTest = currentSuiteTests.get(description); } else { currentTest = null; } }
Example 10
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 11
Source File: JUnitGradeSheetListener.java From public with Apache License 2.0 | 5 votes |
@Override public void testStarted(final Description description) { if (description.isTest() && isGradable(description)) { currentProblems = new ArrayList<>(); } else { currentProblems = null; } }
Example 12
Source File: JUnitGradeSheetListener.java From public with Apache License 2.0 | 5 votes |
@Override public void testStarted(final Description description) { if (description.isTest() && isGradable(description)) { currentTest = currentSuiteTests.get(description); } else { currentTest = null; } }
Example 13
Source File: DynamicTestException.java From bazel with Apache License 2.0 | 5 votes |
/** * 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; }
Example 14
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 15
Source File: TestCoverageProcessEngineRule.java From camunda-bpm-process-test-coverage with Apache License 2.0 | 5 votes |
/** * 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!"); } } }
Example 16
Source File: TestRequestBuilder.java From android-test with Apache License 2.0 | 5 votes |
@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; }
Example 17
Source File: AllureRunListener.java From allure-cucumberjvm with Apache License 2.0 | 5 votes |
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); }
Example 18
Source File: TestSuiteModel.java From bazel with Apache License 2.0 | 5 votes |
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); }
Example 19
Source File: OrchestratedInstrumentationListener.java From android-test with Apache License 2.0 | 5 votes |
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); } } }
Example 20
Source File: TestCoverageProcessEngineRule.java From camunda-bpm-process-test-coverage with Apache License 2.0 | 3 votes |
/** * 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); } }