簡體   English   中英

如何通過 maven surefire 插件運行選定的 suiteXmlFile

[英]How to run a selected suiteXmlFile via maven surefire plugin

我已經完成了關於 SO 的所有相關問題。 但我認為我的問題與其他問題沒有什么不同。

我有以下套件 xml 文件

初始化.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Start" verbose="1" parallel="tests"
    thread-count="5" configfailurepolicy="continue">


    <test name="Initialize" annotations="JDK" preserve-order="true">
        <parameter name="tags" value="not @42" />
        <classes>
            <class name="com.example.runner.InitializeExecution" />
        </classes>
    </test>

</suite>

結束。xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Start" verbose="1" parallel="tests"
    thread-count="5" configfailurepolicy="continue">

    <test name="Conclude" annotations="JDK" preserve-order="true">
        <parameter name="tags" value="not @42" />
        <classes>
            <class name="com.example.runner.ConcludeExecution" />
        </classes>
    </test>

</suite>

煙霧.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="smoke" verbose="1" parallel="tests"
    thread-count="3" configfailurepolicy="continue" data-provider-thread-count="2">


    <test name="Smoke" annotations="JDK" preserve-order="true">
        <parameter name="tags" value="@dm1" />
        <classes>
            <class name="com.example.runner.smoke" />
        </classes>
    </test>


</suite>

回歸.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="smoke" verbose="1" parallel="tests"
    thread-count="3" configfailurepolicy="continue" data-provider-thread-count="2">


    <test name="Regression" annotations="JDK" preserve-order="true">
        <parameter name="tags" value="@dm1" />
        <classes>
            <class name="com.example.runner.regression" />
        </classes>
    </test>


</suite>

pom.xml 片段

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.21.0</version>
                    <configuration>
                        <properties>
                            <property>
                                <name>dataproviderthreadcount</name>
                                <value>2</value>
                            </property>
                        </properties>
                        <suiteXmlFiles>
                            <suiteXmlFile>Initialize.xml</suiteXmlFile>
                            <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
                            <suiteXmlFile>Conclude.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.3</version>
    <!-- <scope>compile</scope> -->
</dependency>

I need to execute initialize.xml then either of smoke.xml or regression.xml then conclude.xml in sequential order. 以以下集合為例:

<suiteXmlFiles>
     <suiteXmlFile>Initialize.xml</suiteXmlFile>
     <suiteXmlFile>smoke.xml</suiteXmlFile>
               <!-- or -->
<!-- <suiteXmlFile>regression.xml</suiteXmlFile> -->
     <suiteXmlFile>Conclude.xml</suiteXmlFile>
</suiteXmlFiles>

如何從 pom 參數化中間 suiteXmlFile? 我嘗試使用以下命令,但它不起作用並引發異常。

mvn clean test -Dsurefire.suiteXmlFile=smoke.test
[ERROR] org.apache.maven.surefire.booter.SurefireExecutionException: Exception in provider
[ERROR]     at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess(InPluginVMSurefireStarter.java:91)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1132)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:978)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:854)
[ERROR]     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
[ERROR]     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR]     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR]     at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR]     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR]     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR]     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
[ERROR]     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
[ERROR]     at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
[ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]     at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR] Caused by: java.lang.NullPointerException
[ERROR]     at org.apache.maven.surefire.testng.TestNGXmlTestSuite.locateTestSets(TestNGXmlTestSuite.java:97)
[ERROR]     at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:119)
[ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]     at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]     at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:206)
[ERROR]     at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:160)
[ERROR]     at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:83)
[ERROR]     at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess(InPluginVMSurefireStarter.java:87)
[ERROR]     ... 25 more
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

如果我使用下面的命令它正在工作但不執行 initialize.xml 和 finally.xml (注意命令中的s

mvn clean test -Dsurefire.suiteXmlFiles=smoke.test

我也嘗試過創建不同的套件 xml 如下所示,並通過命令行傳遞它,但它沒有按我預期的那樣工作。

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

 <suite name="Smoke Suite"  > 
    <suite-files>
           <suite-file path="./Initialize.xml" />
           <suite-file path="./somke.xml" />
           <suite-file path="./Conclude.xml" />
    </suite-files>
</suite>

請幫忙。 任何參考資料或有用的鏈接也值得贊賞。

我們可以做如下的事情嗎,大部分你已經做過了:

<suiteXmlFiles>
     <suiteXmlFile>Initialize.xml</suiteXmlFile>
     <suiteXmlFile>${smokeORregression}</suiteXmlFile>
     <suiteXmlFile>Conclude.xml</suiteXmlFile>
</suiteXmlFiles>

然后根據需要執行mvn clean test -DsmokeORregression=smoke.xmlmvn clean test -DsmokeORregression=regression.xml

mvn 命令中不需要Surefire

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM