Иногда невозможно выполнить тесты maven с использованием тестовой рамки цитрусовых.

Я запускаю тестовые примеры цитрусовых, используя команду maven, которая выглядит так

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

Я выполняю команду выше, используя исполнителя java-процесса, вот код

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, о которой говорилось выше. Проблема, с которой я столкнулся, заключается в том, что остальная служба, используемая как единственный экземпляр, выполняла команду нормально. Но когда я тестировал этот код для нескольких пользователей, то есть в многопоточной среде. Несколько раз каждый пользовательский удар (тесты) выполнялся нормально, но большую часть времени этот код не выполнял все тестовые случаи пользователей (т.е. некоторые тестовые случаи пользователей выполнялись нормально), но для остальных пользователей вывод консоли был таким. Тесты не выполняются. Я использую 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);
    }

    }

person kushma gonna    schedule 23.08.2018    source источник


Ответы (1)


По умолчанию 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

person Christoph Deppisch    schedule 03.09.2018
comment
Nmae класса java — SampleXmlIT.java, поэтому я думаю, что огонь должен выполнять тестовый пример каждый раз, но этого не происходило. - person kushma gonna; 04.09.2018