setTimeOut(testAnnotation.getTimeOut()); m_successPercentage = testAnnotation.getSuccessPercentage(); setInvocationCount(testAnnotation.getInvocationCount()); setThreadPoolSize(testAnnotation.getThreadPoolSize()); setAlwaysRun(testAnnotation.getAlwaysRun()); setDescription(findDescription(testAnnotation, xmlTest)); setEnabled(testAnnotation.getEnabled()); setRetryAnalyzer(testAnnotation.getRetryAnalyzer()); setSkipFailedInvocations(testAnnotation.skipFailedInvocations()); setInvocationTimeOut(testAnnotation.invocationTimeOut()); setIgnoreMissingDependencies(testAnnotation.ignoreMissingDependencies()); setPriority(testAnnotation.getPriority());
@Override public void transform(ITestAnnotation iTestAnnotation, Class aClass, Constructor constructor, Method method) { IRetryAnalyzer retry = iTestAnnotation.getRetryAnalyzer(); if (retry == null) iTestAnnotation.setRetryAnalyzer(Github1600Analyzer.class); } }
private static void ignoreTest(ITestAnnotation annotation, Ignore ignore) { if (ignore == null) { return; } annotation.setEnabled(false); updateDescription(annotation, ignore); }
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { annotation.setRetryAnalyzer(RetryAnalyzer.class); // Enforce default test timeout if (annotation.getTimeOut() == 0) { annotation.setTimeOut(DEFAULT_TEST_TIMEOUT_MILLIS); } } }
private static boolean doesTestAnnotationHaveADataProvider(ITestAnnotation testAnnotation) { return !testAnnotation.getDataProvider().trim().isEmpty() || testAnnotation.getDataProviderClass() != null; }
private static void updateDescription(ITestAnnotation annotation, Ignore ignore) { if (ignore.value().isEmpty()) { return; } String ignoredDescription; if (annotation.getDescription() == null || annotation.getDescription().isEmpty()) { ignoredDescription = ignore.value(); } else { ignoredDescription = ignore.value() + ": " + annotation.getDescription(); } annotation.setDescription(ignoredDescription); }
public void verifyTestMethodLevel() throws SecurityException, NoSuchMethodException { // // Tests on MTest1SampleTest // Method method = MTest1.class.getMethod("f"); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); Assert.assertTrue(test1.getEnabled()); Assert.assertEqualsNoOrder(test1.getGroups(), new String[] { "group1", "group3", "group4", "group2" }); Assert.assertTrue(test1.getAlwaysRun()); Assert.assertEqualsNoOrder(test1.getDependsOnGroups(), new String[] { "dg1", "dg2", "dg3", "dg4" }); Assert.assertEqualsNoOrder(test1.getDependsOnMethods(), new String[] { "dm1", "dm2", "dm3", "dm4" }); Assert.assertEquals(test1.getTimeOut(), 142); Assert.assertEquals(test1.getInvocationCount(), 143); Assert.assertEquals(test1.getSuccessPercentage(), 61); Assert.assertEquals(test1.getDataProvider(), "dp2"); Assert.assertEquals(test1.getDescription(), "Method description"); Class[] exceptions = test1.getExpectedExceptions(); Assert.assertEquals(exceptions.length, 1); Assert.assertEquals(exceptions[0], NullPointerException.class); }
default Class<? extends IRetryAnalyzer> getRetryAnalyzerClass() { return getRetryAnalyzer().getClass(); }
@SuppressWarnings("rawtypes") @Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { String methodName = testMethod.getName(); if (transforms.containsKey(methodName)) { annotation.setEnabled(transforms.get(methodName)); String[] dependencies = annotation.getDependsOnMethods(); for (String dep : dependencies) { transforms.put(dep, true); } } else { // If it is not in the transforms map and defEnabled is true, // do what its annotation says annotation.setEnabled(annotation.getEnabled() && defEnabled); } } }
public class MyAnnotationTransformer implements IAnnotationTransformer { @Override public void transform(ITestAnnotation testAnnotation, Class clazz, Constructor testConstructor, Method method) { testAnnotation.setRetryAnalyzer(TestRepeat.class); } ... }
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { if ( annotation.getTimeOut() == 0 ) { logger.warn("test " + (testMethod == null ? "<null>" : testMethod.toString()) + " has no specified timeout, adding default timeout " + DEFAULT_TIMEOUT / 1000 / 60 + " minutes"); annotation.setTimeOut(DEFAULT_TIMEOUT); } } }
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { if (!annotation.getEnabled()) { return; } Class<?> typedTestClass = testClass; if (testMethod != null) { ignoreTest(annotation, testMethod.getAnnotation(Ignore.class)); typedTestClass = testMethod.getDeclaringClass(); } if (typedTestClass != null) { ignoreTest(annotation, ReflectionHelper.findAnnotation(typedTestClass, Ignore.class)); Package testPackage = typedTestClass.getPackage(); if (testPackage != null) { ignoreTest(annotation, findAnnotation(testPackage)); } } }
/** * @deprecated Unused */ @Deprecated public static String[] dependentGroupsForThisMethodForTest(Method m, IAnnotationFinder finder) { List<String> vResult = Lists.newArrayList(); Class<?> cls = m.getDeclaringClass(); // Collect groups on the class ITestAnnotation tc = AnnotationHelper.findTest(finder, cls); if (null != tc) { for (String group : tc.getDependsOnGroups()) { vResult.add(group); } } // Collect groups on the method ITestAnnotation tm = AnnotationHelper.findTest(finder, m); if (null != tm) { String[] groups = tm.getDependsOnGroups(); for (String group : groups) { vResult.add(group); } } return vResult.toArray(new String[vResult.size()]); }
private String findDescription(ITestAnnotation testAnnotation, XmlTest xmlTest) { String result = testAnnotation.getDescription(); if (result == null) { List<XmlClass> classes = xmlTest.getXmlClasses(); for (XmlClass c : classes) { if (c.getName().equals(m_method.getMethod().getDeclaringClass().getName())) { for (XmlInclude include : c.getIncludedMethods()) { if (include.getName().equals(m_method.getName())) { result = include.getDescription(); if (result != null) { break; } } } } } } return result; }
@SuppressWarnings("rawtypes") public void transform(ITestAnnotation testAnnotation, Class clazz, Constructor constructor, Method method) { if (testAnnotation.getDataProviderClass() == null) { if (testAnnotation instanceof TestAnnotation) { TestAnnotation annotation = (TestAnnotation) testAnnotation; annotation.setDataProviderClass(TestEnricherDataProvider.class); annotation.setDataProvider(TestEnricherDataProvider.PROVIDER_NAME); } } } }
public void verifyTestClassLevel() { // // Tests on MTest1SampleTest // ITestAnnotation test1 = m_finder.findAnnotation(MTest1.class, ITestAnnotation.class); Assert.assertTrue(test1.getEnabled()); Assert.assertEquals(test1.getGroups(), new String[] { "group1", "group2" }); Assert.assertTrue(test1.getAlwaysRun()); Assert.assertEqualsNoOrder(test1.getDependsOnGroups(), new String[] { "dg1", "dg2" }, "depends on groups"); Assert.assertEqualsNoOrder( test1.getDependsOnMethods(), new String[] { "dm1", "dm2" }); Assert.assertEquals(test1.getTimeOut(), 42); Assert.assertEquals(test1.getInvocationCount(), 43); Assert.assertEquals(test1.getSuccessPercentage(), 44); Assert.assertEquals(test1.getThreadPoolSize(), 3); Assert.assertEquals(test1.getDataProvider(), "dp"); Assert.assertEquals(test1.getDescription(), "Class level description"); // // Tests on MTest1SampleTest (test defaults) // ITestAnnotation test2 = m_finder.findAnnotation(MTest2.class, ITestAnnotation.class); // test default for enabled Assert.assertTrue(test2.getEnabled()); Assert.assertFalse(test2.getAlwaysRun()); Assert.assertEquals(test2.getTimeOut(), 0); Assert.assertEquals(test2.getInvocationCount(), 1); Assert.assertEquals(test2.getSuccessPercentage(), 100); Assert.assertEquals(test2.getDataProvider(), ""); }
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { annotation.setRetryAnalyzer(RetryAnalyzer.class); // Enforce default test timeout if (annotation.getTimeOut() == 0) { annotation.setTimeOut(DEFAULT_TEST_TIMEOUT_MILLIS); } } }
private static void updateDescription(ITestAnnotation annotation, Ignore ignore) { if (ignore.value().isEmpty()) { return; } String ignoredDescription; if (annotation.getDescription() == null || annotation.getDescription().isEmpty()) { ignoredDescription = ignore.value(); } else { ignoredDescription = ignore.value() + ": " + annotation.getDescription(); } annotation.setDescription(ignoredDescription); }
@Override public void transform( ITestAnnotation annotation, Class testClass, Constructor tc, Method testMethod, Class<?> clazz) { if (!annotation.getEnabled()) { return; } Class<?> typedTestClass = testClass; if (testMethod != null) { ignoreTest(annotation, testMethod.getAnnotation(Ignore.class)); typedTestClass = testMethod.getDeclaringClass(); } ignoreTestAtClass(typedTestClass, annotation); ignoreTestAtClass(clazz, annotation); }
/** @deprecated Unused */ @Deprecated public static String[] dependentGroupsForThisMethodForTest(Method m, IAnnotationFinder finder) { List<String> vResult = Lists.newArrayList(); Class<?> cls = m.getDeclaringClass(); // Collect groups on the class ITestAnnotation tc = AnnotationHelper.findTest(finder, cls); if (null != tc) { vResult.addAll(Arrays.asList(tc.getDependsOnGroups())); } // Collect groups on the method ITestAnnotation tm = AnnotationHelper.findTest(finder, m); if (null != tm) { String[] groups = tm.getDependsOnGroups(); vResult.addAll(Arrays.asList(groups)); } return vResult.toArray(new String[0]); }