我需要使用 Java 和 SoapUI API 以编程方式创建 SoapUI 测试套件和测试用例。我能够创建 SoapUI 项目并将 WSDL 导入该项目,但我无法理解我使用哪些类来创建测试套件、测试用例、测试步骤和断言。我已阅读 SoapUI API Javadoc,但是否有示例代码片段和/或文档可用于了解我将使用哪些类以及如何使用这些类?
问问题
6180 次
2 回答
1
以下代码生成您的需求:我使用SoapUI Pro的试用版。你不能在免费版本中使用它,因为你会遇到 saveIn 方法的问题:project.saveIn(projectFile);
生成 XML 文件
/**
* Creates a SoapUI-Project with a TestSuite and a TestCase for each operation the webservice provides
* @param projectFileName The xml-file where to save the project
* @param wsdlName for example: http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL
* @param projectName The name of the project
* @param suiteName The name of the TestSuite
* @param caseName The prefix for the TestCase name
* @param stepname The prefix for the TestStep name
* @throws Exception
*/
public void createProject(String projectFileName, String wsdlName, String projectName, String suiteName, String caseName, String stepname) throws Exception{
// create File
File projectFile = new File(projectFileName);
SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
WsdlProject project = new WsdlProject();
project.setName(projectName);
WsdlInterface wsdl = WsdlInterfaceFactory.importWsdl(project, wsdlName,true)[0];
int c = wsdl.getOperationCount();
WsdlTestSuite TS = project.addNewTestSuite(suiteName);
TS.setName(suiteName);
for (int i = 0; i < c; i++) {
WsdlOperation operation = wsdl.getOperationAt(i);
String opName = operation.getName();
// Create new TestCase and the specified TestStep
TestStepConfig testStepConfig = WsdlTestRequestStepFactory.createConfig(operation, caseName+opName);
WsdlTestCase testCase = TS.addNewTestCase(caseName+opName);
WsdlTestStep testStep = testCase.addTestStep(testStepConfig);
testStep.setName(stepname+opName);
}
project.saveIn(projectFile);
}
您还需要以下 maven pom.xml 依赖项:
<dependencies>
<dependency>
<groupId>eviware</groupId>
<artifactId>maven-soapui-plugin</artifactId>
<version>4.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>eviware</id>
<url>http://www.eviware.com/repository/maven2/</url>
</repository>
</repositories>
于 2014-05-12T06:50:14.830 回答
0
我会尝试从这个http://www.soapui.org/Developers-Corner/integrating-with-soapui.html开始。但老实说,我不得不说我只使用了 SoapUI GUI。
于 2013-10-17T05:14:05.283 回答