Java Code Examples for org.junit.runner.Description#getAnnotations()
The following examples show how to use
org.junit.runner.Description#getAnnotations() .
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: RunAsFullyAuthenticatedRule.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * * @param description the description object from JUnit * @return the username specified in the {@link RunAsUser} annotation, if there was one, else <code>null</code>. */ private String getMethodAnnotatedUserName(Description description) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { String result = null; Collection<Annotation> annotations = description.getAnnotations(); for (Annotation anno : annotations) { if (anno.annotationType().equals(RunAsUser.class)) { result = (String) anno.annotationType().getMethod("userName").invoke(anno); } } return result; }
Example 2
Source File: AllureRunListener.java From allure-cucumberjvm with Apache License 2.0 | 6 votes |
@Override public void testStarted(Description description) throws IllegalAccessException { if (description.isTest()) { String methodName = extractMethodName(description); TestCaseStartedEvent event = new TestCaseStartedEvent(getSuiteUid(description), methodName); event.setTitle(methodName); Collection<Annotation> annotations = new ArrayList<>(); for (Annotation annotation : description.getAnnotations()) { annotations.add(annotation); } AnnotationManager am = new AnnotationManager(annotations); am.update(event); getLifecycle().fire(event); } }
Example 3
Source File: TestRequestBuilder.java From android-test with Apache License 2.0 | 6 votes |
@Override protected boolean evaluateTest(Description description) { // If test method is annotated with test size annotation include it if (testSize.testMethodIsAnnotatedWithTestSize(description)) { return true; } else if (testSize.testClassIsAnnotatedWithTestSize(description)) { // size annotation matched at class level. Make sure method doesn't have any other // size annotations for (Annotation a : description.getAnnotations()) { if (TestSize.isAnyTestSize(a.annotationType())) { return false; } } return true; } return false; }
Example 4
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 5
Source File: JUnitBenchmarkProvider.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
@Override public Statement apply(Statement base, Description description) { Class<?> clazz = description.getTestClass(); String mname = description.getMethodName(); Collection<Annotation> annotations = description.getAnnotations(); final int rounds = getRoundsForFullMethodName(clazz.getCanonicalName() + "." + mname); List<Annotation> modifiedAnnotations = new ArrayList<Annotation>(annotations.size()); boolean hit = false; for (Annotation a : annotations) { if (a.annotationType().equals(BenchmarkOptions.class)) { final BenchmarkOptions old = (BenchmarkOptions)a; BenchmarkOptions replacement = getWrappedBenchmarkOptions(old, rounds); modifiedAnnotations.add(replacement); log.debug("Modified BenchmarkOptions annotation on {}", mname); hit = true; } else { modifiedAnnotations.add(a); log.debug("Kept annotation {} with annotation type {} on {}", new Object[] { a, a.annotationType(), mname }); } } if (!hit) { BenchmarkOptions opts = getDefaultBenchmarkOptions(rounds); modifiedAnnotations.add(opts); log.debug("Added BenchmarkOptions {} with annotation type {} to {}", new Object[] { opts, opts.annotationType(), mname }); } Description roundsAdjustedDesc = Description.createTestDescription( clazz, mname, modifiedAnnotations.toArray(new Annotation[modifiedAnnotations.size()])); return rule.apply(base, roundsAdjustedDesc); }
Example 6
Source File: AllureRunListener.java From allure-cucumberjvm with Apache License 2.0 | 5 votes |
public void testSuiteStarted(Description description, String suiteName) throws IllegalAccessException { String[] annotationParams = findFeatureByScenarioName(suiteName); //Create feature and story annotations. Remove unnecessary words from it Features feature = getFeaturesAnnotation(new String[]{annotationParams[0].split(":")[1].trim()}); Stories story = getStoriesAnnotation(new String[]{annotationParams[1].split(":")[1].trim()}); //If it`s Scenario Outline, add example string to story name if (description.getDisplayName().startsWith("|") || description.getDisplayName().endsWith("|")) { story = getStoriesAnnotation(new String[]{annotationParams[1].split(":")[1].trim() + " " + description.getDisplayName()}); } String uid = generateSuiteUid(suiteName); TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, story.value()[0]); event.setTitle(story.value()[0]); //Add feature and story annotations Collection<Annotation> annotations = new ArrayList<>(); for (Annotation annotation : description.getAnnotations()) { annotations.add(annotation); } annotations.add(story); annotations.add(feature); AnnotationManager am = new AnnotationManager(annotations); am.update(event); event.withLabels(AllureModelUtils.createTestFrameworkLabel("CucumberJVM")); getLifecycle().fire(event); }
Example 7
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 8
Source File: AllureRunListener.java From allure1 with Apache License 2.0 | 5 votes |
@Override public void testStarted(Description description) { TestCaseStartedEvent event = new TestCaseStartedEvent(getSuiteUid(description), description.getMethodName()); AnnotationManager am = new AnnotationManager(description.getAnnotations()); am.update(event); fireClearStepStorage(); getLifecycle().fire(event); }
Example 9
Source File: AllureRunListener.java From allure1 with Apache License 2.0 | 5 votes |
public void startFakeTestCase(Description description) { String uid = getSuiteUid(description); String name = description.isTest() ? description.getMethodName() : description.getClassName(); TestCaseStartedEvent event = new TestCaseStartedEvent(uid, name); AnnotationManager am = new AnnotationManager(description.getAnnotations()); am.update(event); fireClearStepStorage(); getLifecycle().fire(event); }
Example 10
Source File: UiThreadRule.java From pretty with MIT License | 5 votes |
@Override public Statement apply(final Statement statement, Description description) { Collection<Annotation> annotations = description.getAnnotations(); for (Annotation annotation : annotations) { if (UiThreadTest.class.equals(annotation.annotationType())) { return new Statement() { @Override public void evaluate() throws Throwable { final Throwable[] t = new Throwable[1]; instrumentation.runOnMainSync(new Runnable() { @Override public void run() { try { statement.evaluate(); } catch (Throwable throwable) { t[0] = throwable; } } }); if (t[0] != null) { throw t[0]; } } }; } } return statement; }
Example 11
Source File: LoadTestRule.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Statement apply(final Statement base, final Description description) { boolean loadTestingRequestedForThisMethod = false; Collection<Annotation> annotations = description.getAnnotations(); for (Annotation anno : annotations) { if (anno.annotationType().equals(LoadTest.class)) { loadTestingRequestedForThisMethod = true; } } if (loadTestingRequestedForThisMethod) { log.debug(LoadTest.class.getSimpleName() + "-based testing configured for method " + description.getMethodName()); return new Statement() { @Override public void evaluate() throws Throwable { int executionCount = getCount(); int currentIndex = 1; final CountDownLatch latch = new CountDownLatch(executionCount); for (String username: people.getUsernames()) { log.debug("About to start " + description.getMethodName() + ". " + currentIndex + "/" + executionCount + " as " + username); new Thread(new StatementEvaluatorRunnable(username, base, latch)).start(); currentIndex++; } latch.await(); verify(); } }; } else { log.debug(LoadTest.class.getSimpleName() + "-based testing NOT configured for this method."); return base; } }
Example 12
Source File: RuleUsingAnnotationsTest.java From burst with Apache License 2.0 | 4 votes |
@Override protected void starting(Description description) { annotations = description.getAnnotations(); }
Example 13
Source File: AllureMarathonRunListener.java From marathonv5 with Apache License 2.0 | 3 votes |
public void testSuiteStarted(Description description) { String uid = generateSuiteUid(getSuiteName(description)); TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, getSuiteName(description)); AnnotationManager am = new AnnotationManager(description.getAnnotations()); am.update(event); event.withLabels(AllureModelUtils.createTestFrameworkLabel("Marathon")); getLifecycle().fire(event); }
Example 14
Source File: AllureRunListener.java From allure1 with Apache License 2.0 | 3 votes |
public void testSuiteStarted(Description description) { String uid = generateSuiteUid(description.getClassName()); TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, description.getClassName()); AnnotationManager am = new AnnotationManager(description.getAnnotations()); am.update(event); event.withLabels(AllureModelUtils.createTestFrameworkLabel("JUnit")); getLifecycle().fire(event); }