org.testng.annotations.Test.expectedExceptions()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(2.5k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中org.testng.annotations.Test.expectedExceptions()方法的一些代码示例,展示了Test.expectedExceptions()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Test.expectedExceptions()方法的具体详情如下:
包路径:org.testng.annotations.Test
类名称:Test
方法名:expectedExceptions

Test.expectedExceptions介绍

暂无

代码示例

代码示例来源:origin: selenide/selenide

boolean shouldIntercept(Method testMethod) {
 if (testMethod == null) return false;
 
 Test annotation = testMethod.getAnnotation(Test.class);
 return annotation != null && asList(annotation.expectedExceptions()).isEmpty();
}

代码示例来源:origin: org.testng/testng

result.setDescription(
  findInherited(test.description(), cls, Test.class, "description", DEFAULT_STRING));
result.setExpectedExceptions(test.expectedExceptions());
result.setExpectedExceptionsMessageRegExp(test.expectedExceptionsMessageRegExp());
result.setSuiteName(test.suiteName());

代码示例来源:origin: cbeust/testng

result.setDescription(
  findInherited(test.description(), cls, Test.class, "description", DEFAULT_STRING));
result.setExpectedExceptions(test.expectedExceptions());
result.setExpectedExceptionsMessageRegExp(test.expectedExceptionsMessageRegExp());
result.setSuiteName(test.suiteName());

代码示例来源:origin: jmockit/jmockit1

private static boolean isExpectedException(@Nonnull IInvokedMethod invokedMethod, @Nonnull Throwable thrownByTest) {
 Method testMethod = invokedMethod.getTestMethod().getConstructorOrMethod().getMethod();
 Class<?>[] expectedExceptions = testMethod.getAnnotation(Test.class).expectedExceptions();
 Class<? extends Throwable> thrownExceptionType = thrownByTest.getClass();
 for (Class<?> expectedException : expectedExceptions) {
   if (expectedException.isAssignableFrom(thrownExceptionType)) {
    return true;
   }
 }
 return false;
}

代码示例来源:origin: org.powermock/powermock-module-testng

public String[] getPackagesToIgnore(AnnotatedElement element) {
    List<String> ignoredPackages = new LinkedList<String>();
    if (element instanceof Class<?>) {
      Class<?> klazz = (Class<?>) element;
      for (Method method : klazz.getMethods()) {
        Test annotation = method.getAnnotation(Test.class);
        if (annotation != null) {
          Class<?>[] ignores = annotation.expectedExceptions();
          if (ignores != null) {
            for (Class<?> ignorePackage : ignores) {
              ignoredPackages.add(ignorePackage.getName());
            }
          }
        }
      }
      Class<?> superclass = klazz.getSuperclass();
      if (superclass != null && !superclass.equals(Object.class)) {
        String[] packagesToIgnore = getPackagesToIgnore(superclass);
        ignoredPackages.addAll(Arrays.asList(packagesToIgnore));
      }
    }

    return ignoredPackages.toArray(new String[ignoredPackages.size()]);
  }
}

相关文章