【问题标题】:Specify tag for test cases using soapui-pro-maven-plugin使用 soapui-pro-maven-plugin 为测试用例指定标签
【发布时间】:2016-08-31 12:36:24
【问题描述】:

可以像这样在 SOAP UI 中为测试用例指定标签:

我正在使用 SOAP UI Maven 插件在不同的环境中执行功能测试套件,如果能够通过在调用中指定标签来排除某些测试用例,将会很有用。

Maven 插件似乎没有配置参数来指定标签(因此只能执行跨跨不同测试套件的测试子集):

https://www.soapui.org/test-automation/maven/maven-2-x.html

但是,通过 GUI 或命令行运行时可以指定标签:

http://readyapi.smartbear.com/features/automation/testrunner/cli

您可以从上面的链接中看到,可以指定使用 -T 开关标记的测试。

这只是 Maven 插件的限制吗?

是否可以通过在 Groovy 启动脚本执行期间读取环境变量并禁用没有指定标签的测试用例来模拟指定标签?

Maven调用如下:

mvn test -Dmyenv="dev" com.smartbear.soapui:soapui-pro-maven-plugin:5.2.1:test

pom.xml 如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>testing</groupId>
<artifactId>testing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<prerequisites>
    <maven>3.0.5</maven>
</prerequisites>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<pluginRepositories>
    <pluginRepository>
        <id>SmartBearPluginRepository</id>
        <url>http://www.soapui.org/repository/maven2/</url>
    </pluginRepository>
    <pluginRepository>
        <id>mvnPluginRepository</id>
        <url>http://mirrors.ibiblio.org/pub/mirrors/maven/mule/dependencies/maven2/</url>
    </pluginRepository>
    <pluginRepository>
        <id>codehausPluginRepository</id>
        <url>https://nexus.codehaus.org/content/groups/snapshots-group/org/codehaus/mojo/</url>
    </pluginRepository>
</pluginRepositories>
<build>
    <plugins>
        <plugin>
            <groupId>com.smartbear.soapui</groupId>
            <artifactId>soapui-pro-maven-plugin</artifactId>
            <version>5.2.1</version>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.6</version>
                </dependency>
                <dependency>
                    <groupId>postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>9.1-901-1.jdbc4</version>
                </dependency>
                <dependency>
                    <groupId>org.reflections</groupId>
                    <artifactId>reflections-maven</artifactId>
                    <version>0.9.9-RC1</version>
                </dependency>
            </dependencies>
            <configuration>
                <projectFile>${basedir}/my-project</projectFile>
                <outputFolder>${basedir}/surefire-reports</outputFolder>
                <printReport>true</printReport>
                <junitReport>true</junitReport>
                <exportAll>true</exportAll>
                <reportFormat>HTML</reportFormat>
                <testFailIgnore>true</testFailIgnore>
                <coverage>true</coverage>
                <environment>${myenv}</environment>
            </configuration>
            <executions>
                <execution>
                    <phase>test</phase>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.10</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
    </plugins>
</build>

【问题讨论】:

标签: java maven automated-tests soapui


【解决方案1】:

您是否希望为 Surefire 插件指定环境变量?如果是这样,这应该工作:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>-Dmyenv=dev</argLine>
    </configuration>
</plugin>

【讨论】:

    【解决方案2】:

    如果我对此有任何错误或有更好的方法,请纠正我,因为我对使用 SOAP UI 比较陌生。如果你给出一个明显更好的答案,我会接受你的。我真的希望 Smartbear 能够支持在 Maven 插件中指定标签的方式。

    我已经确定它是not possible to specify a tag via the Maven plugin,并且SOAP UI 的服务器版本的成本是large amount of money,所以在我的情况下不可能使用指定标签的命令行方法。

    我考虑通过将我想要为环境包含/排除的所有测试移动到多个测试套件来模拟测试标签/类别。不幸的是,似乎只能运行一个测试套件(通过指定一个“testSuite”参数)或所有测试套件(通过将“testSuite”留空)。

    我认为我可以使用 Groovy 脚本提取测试用例或套件的标签,并使用它来确定是否应该运行它,但据我所知,这是不可能的测试用例或 testSuite 的标签信息 (object modelAPI documentation)。

    我决定使用自定义属性 (testingOnly) 标记要排除的测试套件,并在项目级别“设置脚本”中禁用特定环境 (Dev) 的测试套件:

    // When running tests for the Dev environment, skip test suites with the property testingOnly=true
    
    def disableSuitesWithProperty(def propertyName) {
        project.testSuiteList.each { testSuite ->
            def isPropertyTrue = testSuite.getProperty(propertyName)?.getValue()?.toBoolean() ?: false;
    
            if(isPropertyTrue) {
                log.info "[Project Setup Script] Will Skip Test Suite: ${testSuite.name}";
                testSuite.setDisabled(true);
            }
            else {
                log.info "[Project Setup Script] Will Execute Test Suite: ${testSuite.name}";
                testSuite.setDisabled(false);
            }
        }
    }
    
    if ("Dev".equals(project.getActiveEnvironmentName())) {
        disableSuitesWithProperty("testingOnly");
    }
    

    套件在项目级别“TearDown Script”中重新启用:

    // Reenable all test suites after all tests have run
    
    for (testSuite in project.testSuiteList) {
        log.info "[Project TearDown Script] Reenabling Test Suite: ${testSuite.name}";
        testSuite.setDisabled(false);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多