使用柑橘测试框架工作无法在某些时候执行maven测试

问题描述 投票:0回答:1

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

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

我正在执行上面的命令使用java procesess 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);

我将上面的代码暴露为休息服务。 user通过url发送系统属性。我使用maven命令将该信息传递给maven fail safe plugin这里是maven fail safe plugin属性。

 <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命令。我面临的问题是当其余服务用作单个实例时,命令执行正常。但是,当我为多用户测试此代码时,即在多线程环境中。有时每个用户点击(测试)执行正常,但大多数时候这段代码没有执行所有用户测试用例(即一些用户的测试用例都很好)但是对于用户来说,控制台输出就是这样的。没有执行测试。我正在使用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);
    }

    }
maven testng maven-plugin maven-failsafe-plugin citrus-framework
1个回答
0
投票

默认情况下,maven-failsafe-plugin将仅使用以下通配符模式执行测试类:

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

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

您可以将maven-failsafe-plugin配置为使用不同的命名模式。请在https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html了解如何执行此操作

© www.soinside.com 2019 - 2024. All rights reserved.