可以在 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>
最佳答案
如果我对此有任何错误,或者是否有更好的方法,请纠正我,因为我对使用 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 model API 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);
}
关于java - 使用soapui-pro-maven-plugin指定测试用例的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37055407/