自动化工具 testng 集成 allure,运行 testng.xml 报错,哪位大佬碰到过这个问题吗?

suihansongmao · 2018年05月04日 · 最后由 suihansongmao 回复于 2018年08月30日 · 3584 次阅读

代码里还集成了其他东西,没集成 allure 之前是可以正常跑通的
这是 pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.zct.apitest</groupId>
    <artifactId>api</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <tesgng.version>6.14.2</tesgng.version>
        <mysql.version>6.0.6</mysql.version>
        <druid.version>1.1.9</druid.version>
        <mybatis.version>3.4.5</mybatis.version>
        <okhttp.version>3.10.0</okhttp.version>
        <aspectj.version>1.8.10</aspectj.version>
        <fastjson.version>1.2.47</fastjson.version>
        <allure-testng.version>2.6.0</allure-testng.version>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
        <!-- allure -->
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>${allure-testng.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${tesgng.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>${okhttp.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>


这是报错信息:
[AppClassLoader@4629104a] error at io\qameta\allure\aspects\StepsAspects.java::0 the @annotation pointcut expression is only supported at Java 5 compliance level or above
[AppClassLoader@4629104a] error at io\qameta\allure\aspects\AttachmentsAspects.java::0 the @annotation pointcut expression is only supported at Java 5 compliance level or above
[DelegatingClassLoader@5a45133e] error at io\qameta\allure\aspects\StepsAspects.java::0 the @annotation pointcut expression is only supported at Java 5 compliance level or above
[DelegatingClassLoader@5a45133e] error at io\qameta\allure\aspects\AttachmentsAspects.java::0 the @annotation pointcut expression is only supported at Java 5 compliance level or above
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.util.ServiceConfigurationError: org.testng.ITestNGListener: Provider io.qameta.allure.testng.AllureTestNg could not be instantiated
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:581)
at java.base/java.util.ServiceLoader.access$100(ServiceLoader.java:390)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:803)
at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:721)
at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1394)
at org.testng.TestNG.addServiceLoaderListeners(TestNG.java:967)
at org.testng.TestNG.initializeConfiguration(TestNG.java:906)
at org.testng.TestNG.initializeEverything(TestNG.java:996)
at org.testng.TestNG.run(TestNG.java:1009)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.(JaxbAnnotationIntrospector.java:139)
at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.(JaxbAnnotationIntrospector.java:126)
at io.qameta.allure.model.Allure2ModelJackson.createMapper(Allure2ModelJackson.java:26)
at io.qameta.allure.FileSystemResultsWriter.(FileSystemResultsWriter.java:30)
at io.qameta.allure.AllureLifecycle.getDefaultWriter(AllureLifecycle.java:281)
at io.qameta.allure.AllureLifecycle.(AllureLifecycle.java:47)
at io.qameta.allure.Allure.getLifecycle(Allure.java:30)
at io.qameta.allure.testng.AllureTestNg.(AllureTestNg.java:119)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:779)
... 8 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlElement
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 21 more

Process finished with exit code 0
Empty test suite.
PS:第一次发,如果有什么不规范的,麻烦指出来,我马上改

共收到 3 条回复 时间 点赞
仅楼主可见

初步估计需要在 pom.xml 文件里面加入 maven compile 插件,jdk 版本设置到 1.8

<build>

   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>3.7.0</version>
       <configuration>
         <source>1.8</source>
         <target>1.8</target>
       </configuration>
     </plugin>
   </plugins>

 </build>

终于解决问题了,虽然还是知其然,不知其所以然的阶段,下面贴上问题及解决办法:

问题 1:[AppClassLoader@4629104a] error at io\qameta\allure\aspects\StepsAspects.java::0 the @annotation pointcut expression is only supported at Java 5 compliance level or above

[AppClassLoader@4629104a] error at io\qameta\allure\aspects\AttachmentsAspects.java::0 the @annotation pointcut expression is only supported at Java 5 compliance level or above
[DelegatingClassLoader@5a45133e] error at io\qameta\allure\aspects\StepsAspects.java::0 the @annotation pointcut expression is only supported at Java 5 compliance level or above
[DelegatingClassLoader@5a45133e] error at io\qameta\allure\aspects\AttachmentsAspects.java::0 the @annotation pointcut expression is only supported at Java 5 compliance level or above
解决方案 1:将 pom 文件中 aspectj 版本改成 1.9.1
参考:https://blog.csdn.net/benjamin_whx/article/details/23256799

问题 2:SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
解决方案 2:在 pom 文件中加上依赖:

<dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.5</version>
</dependency>

参考:https://blog.csdn.net/menofgod/article/details/81288692#comments

问题 3:java.util.ServiceConfigurationError: org.testng.ITestNGListener: Provider io.qameta.allure.testng.AllureTestNg could not be instantiated

解决方案 3:在 pom 文件中加上

<dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
</dependency>

参考:https://stackoverflow.com/questions/47341559/allure-testng-maven-org-testng-itestnglistener-provider-io-qameta-allure-testn
希望帮到有同样困惑的旁友

suihansongmao 关闭了讨论 07月04日 20:00
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册