当前位置: 首页 > 知识库问答 >
问题:

使用maven运行testng suite xml时,maven-surefire-plugin中的NullPointerException

禄源
2023-03-14

当我使用maven运行我的testng套件xml时,在suite标记中没有parallel=“tests”时,我会出现异常。

> [ERROR] Failed to execute goal
> org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test
> (default-test) on project neo: Execution default-test of goal
> org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed:
> There was an error in the forked process [ERROR]
> java.lang.NullPointerException [ERROR] at
> java.util.Hashtable.put(Hashtable.java:514) [ERROR] at
> java.util.Properties.setProperty(Properties.java:161) [ERROR] at
> org.testng.reporters.JUnitXMLReporter.createElement(JUnitXMLReporter.java:203)
> [ERROR] at
> org.testng.reporters.JUnitXMLReporter.generateReport(JUnitXMLReporter.java:181)
> [ERROR] at
> org.testng.reporters.JUnitXMLReporter.onFinish(JUnitXMLReporter.java:118)
> [ERROR] at org.testng.TestRunner.fireEvent(TestRunner.java:1246)
> [ERROR] at org.testng.TestRunner.afterRun(TestRunner.java:1039)
> [ERROR] at org.testng.TestRunner.run(TestRunner.java:621) [ERROR] at
> org.testng.SuiteRunner.runTest(SuiteRunner.java:334) [ERROR] at
> org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) [ERROR]
> at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) [ERROR] at
> org.testng.SuiteRunner.run(SuiteRunner.java:240) [ERROR] at
> org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
> [ERROR] at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
> [ERROR] at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
> [ERROR] at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
> [ERROR] at org.testng.TestNG.run(TestNG.java:1031) [ERROR] at
> org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)
> [ERROR] at
> org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
> [ERROR] at
> org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)
> [ERROR] at
> org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
> [ERROR] at
> org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
> [ERROR] at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)

当我用parallel=“tests”运行它时,它工作得很好。此外,如果我在没有parallel=“tests”的情况下从eclipse“Run as testng Test”运行我的testng套件xml,它工作得很好。请帮忙。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Filters API" parallel="tests">
    <test name="Filters Test">
        <classes>
            <class name="com.api.testng.modules.filters.FiltersTests"/>
        </classes>
    </test>
</suite>

共有1个答案

张和豫
2023-03-14

我在pom中提到插件的这一部分-

        <profile>
        <id>TestNg</id>
        <activation>
            <property>
                <name>run_tests</name>
                <value>TestNg</value>
            </property>
        </activation>
        <dependencies>
            <dependency>
                <groupId>ru.yandex.qatools.allure</groupId>
                <artifactId>allure-testng-adaptor</artifactId>
                <version>${allure.version}</version>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.0</version>
                    <configuration>
                        <testIncludes>
                            <testInclude>**/testng/**</testInclude>
                        </testIncludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${surefire.version}</version>
                    <configuration>
                        <testFailureIgnore>false</testFailureIgnore>
                        <argLine>
                            -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                        </argLine>
                        <properties>
                            <property>
                                <name>listener</name>
                                <value>ru.yandex.qatools.allure.testng.AllureTestListener</value>
                            </property>
                        </properties>
                        <suiteXmlFiles>
                            <suiteXmlFile>
                                ${suite.xml}
                            </suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjweaver</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
 类似资料: