有时无法使用柑桔类测试框架执行Maven测试

时间:2018-08-23 19:24:01

标签: maven testng maven-plugin maven-failsafe-plugin citrus-framework

我正在使用看起来像这样的maven命令运行柑橘测试用例

mvn integration-test -Dfilename.pattern=**/*Rest.xml -Dhtmlreport.name=report4.html

我正在使用java procedess executor执行以上命令,这是代码

public class TestExecutor {
    String[] command = new String[3];
             command[0] = "cmd";
             command[1] = "/c";
             command[2] = "mvn integration-test -Dfilename.pattern=**/*"+xmlName+" "+"-Dhtmlreport.name="+report_name;

}

         Process p = Runtime.getRuntime().exec(command);

我将上述代码公开为休息服务。用户通过url发送系统属性。我正在使用maven命令将该信息传递给maven故障安全插件,这是maven故障安全插件的属性。

 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.20</version>
           <configuration>
                <systemProperties>
              <citrus.xml.file.name.pattern>${filename.pattern}</citrus.xml.file.name.pattern>
              <citrus.html.report.file>${htmlreport.name}</citrus.html.report.file>
             </systemProperties>
            </configuration>

            <executions>
              <execution>
                <id>integration-tests</id>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

我的休息服务收到此信息后,将执行上面提到的maven命令。我面临的问题是,将rest服务用作单个实例时,命令执行得很好。但是当我为多用户测试此代码时,即在多线程环境中。有时候,每个用户命中(Tests)的执行情况都很好,但是大多数情况下,这段代码并未执行所有用户的测试用例(即某些用户的测试用例正在正常执行),但是对于其余用户,控制台的输出就是这样。没有执行测试。我正在使用testNg执行我的测试用例。

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------< com.walmart.citrus:multi-user-handling >---------------
[INFO] Building Citrus Integration Test 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ multi-user-handling ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ multi-user-handling ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to D:\springnotes\multi-user-handling\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ multi-user-handling ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ multi-user-handling ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.20:test (default-test) @ multi-user-handling ---
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ multi-user-handling ---
[INFO] 
[INFO] --- maven-failsafe-plugin:2.20:integration-test (integration-tests) @ multi-user-handling ---
[WARNING] The parameter forkMode is deprecated since version 2.14. Use forkCount and reuseForks instead.
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting.outputEncoding}.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 48.568 s
[INFO] Finished at: 2018-08-23T23:41:20+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "test" could not be activated because it does not exist.  

对于成功执行测试用例的其余用户,就像这样

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------< com.citrus:multi-user-handling >---------------
[INFO] Building Citrus Integration Test 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ multi-user-handling ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ multi-user-handling ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ multi-user-handling ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ multi-user-handling ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.20:test (default-test) @ multi-user-handling ---
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ multi-user-handling ---
[INFO] 
[INFO] --- maven-failsafe-plugin:2.20:integration-test (integration-tests) @ multi-user-handling ---
[WARNING] The parameter forkMode is deprecated since version 2.14. Use forkCount and reuseForks instead.
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.walmart.tests.SampleXmlIT
23:41:11,094 INFO         citrus.Citrus| Unable to locate Citrus application properties
23:41:11,137 INFO  BeanDefinitionReader| Loading XML bean definitions from URL [file:/D:/springnotes/multi-user-handling/target/test-classes/citrus-context.xml]
23:41:11,709 DEBUG BeanDefinitionReader| Loaded 0 bean definitions from location pattern [classpath*:citrus-context.xml]
23:41:13,545 INFO  port.LoggingReporter| 
23:41:13,545 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:13,545 INFO  port.LoggingReporter|        .__  __                       
23:41:13,545 INFO  port.LoggingReporter|   ____ |__|/  |________ __ __  ______
23:41:13,545 INFO  port.LoggingReporter| _/ ___\|  \   __\_  __ \  |  \/  ___/
23:41:13,545 INFO  port.LoggingReporter| \  \___|  ||  |  |  | \/  |  /\___ \ 
23:41:13,545 INFO  port.LoggingReporter|  \___  >__||__|  |__|  |____//____  >
23:41:13,545 INFO  port.LoggingReporter|      \/                           \/
23:41:13,545 INFO  port.LoggingReporter| 
23:41:13,545 INFO  port.LoggingReporter| C I T R U S  T E S T S  2.7.3
23:41:13,546 INFO  port.LoggingReporter| 
23:41:13,546 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:13,546 DEBUG port.LoggingReporter| BEFORE TEST SUITE
23:41:13,546 INFO  port.LoggingReporter| 
23:41:13,546 INFO  port.LoggingReporter| 
23:41:13,546 INFO  port.LoggingReporter| BEFORE TEST SUITE: SUCCESS
23:41:13,546 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:13,546 INFO  port.LoggingReporter| 
23:41:13,582 DEBUG t.TestContextFactory| Created new test context - using global variables: '{}'
23:41:14,618 INFO  port.LoggingReporter| 
23:41:14,618 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:14,618 DEBUG port.LoggingReporter| STARTING TEST 20180326024725Rest <com\walmart\resources>
23:41:14,618 INFO  port.LoggingReporter| 
23:41:14,618 DEBUG      citrus.TestCase| Initializing test case
23:41:14,619 DEBUG  context.TestContext| Setting variable: citrus.test.name with value: '20180326024725Rest'
23:41:14,619 DEBUG  context.TestContext| Setting variable: citrus.test.package with value: 'com\walmart\resources'
23:41:14,619 DEBUG      citrus.TestCase| Test variables:
23:41:14,619 DEBUG      citrus.TestCase| citrus.test.name = 20180326024725Rest
23:41:14,619 DEBUG      citrus.TestCase| citrus.test.package = com\test\resources
23:41:14,619 INFO  port.LoggingReporter| 
23:41:14,619 DEBUG port.LoggingReporter| TEST STEP 1/1: echo
23:41:14,620 INFO    actions.EchoAction| 
hmmm

23:41:14,620 INFO  port.LoggingReporter| 
23:41:14,620 DEBUG port.LoggingReporter| TEST STEP 1/1 SUCCESS
23:41:14,621 INFO  port.LoggingReporter| 
23:41:14,621 INFO  port.LoggingReporter| TEST SUCCESS 20180326024725Rest (com\walmart\resources)
23:41:14,621 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:14,621 INFO  port.LoggingReporter| 
[TestHTMLReporter] Access is denied
23:41:15,207 INFO  port.LoggingReporter| 
23:41:15,207 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:15,208 DEBUG port.LoggingReporter| AFTER TEST SUITE
23:41:15,208 INFO  port.LoggingReporter| 
23:41:15,208 INFO  port.LoggingReporter| 
23:41:15,208 INFO  port.LoggingReporter| AFTER TEST SUITE: SUCCESS
23:41:15,208 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:15,209 INFO  port.LoggingReporter| 
23:41:15,209 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:15,209 INFO  port.LoggingReporter| 
23:41:15,209 INFO  port.LoggingReporter| CITRUS TEST RESULTS
23:41:15,209 INFO  port.LoggingReporter| 
23:41:15,212 INFO  port.LoggingReporter|  20180326024725Rest ............................................. SUCCESS
23:41:15,212 INFO  port.LoggingReporter| 
23:41:15,212 INFO  port.LoggingReporter| TOTAL: 1
23:41:15,212 DEBUG port.LoggingReporter| SKIPPED:   0 (0.0%)
23:41:15,212 INFO  port.LoggingReporter| FAILED:    0 (0.0%)
23:41:15,212 INFO  port.LoggingReporter| SUCCESS:   1 (100.0%)
23:41:15,212 INFO  port.LoggingReporter| 
23:41:15,212 INFO  port.LoggingReporter| ------------------------------------------------------------------------
23:41:15,212 DEBUG  report.HtmlReporter| Generating HTML test report
23:41:15,213 DEBUG       util.FileUtils| Reading file resource: 'test-detail.html' (encoding is 'windows-1252')
23:41:15,584 DEBUG       util.FileUtils| Reading file resource: 'test-report.html' (encoding is 'windows-1252')
23:41:15,591 INFO   report.HtmlReporter| Generated HTML test report: target\citrus-reports\report8.html
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.61 s - in com.walmart.tests.SampleXmlIT
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[WARNING] Could not delete temp directory D:\springnotes\multi-user-handling\target\surefire because Directory D:\springnotes\multi-user-handling\target\surefire unable to be deleted.
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting.outputEncoding}.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 51.719 s
[INFO] Finished at: 2018-08-23T23:41:19+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "test" could not be activated because it does not exist.

这是我的休息服务代码

@RestController
public class RestRunner {
    static  String namePattern="";

    @RequestMapping(value="runurtest", method=RequestMethod.GET)
    @ResponseBody
    public String rest(@RequestParam String xmlName,@RequestParam String report_name) throws Exception

    {
    //TestExecutor class executes maven command in java procesess
        new TestExecutor().exec(xmlName,report_name);

      //report manger class sends html report user
        return new ReportManager().readHTMLFile(report_name);
    }

    }

1 个答案:

答案 0 :(得分:0)

默认情况下,maven-failsafe-plugin仅执行具有以下通配符模式的测试类:

**/IT*.java **/*IT.java **/*ITCase.java

如果您的测试类未遵循任何这些命名约定,则故障保护将不会执行测试。

您可以将maven-failsafe-plugin配置为使用不同的命名模式。请在https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html

中查看操作方法