如何使用SoapUI API创建测试套件,测试用例,测试步骤和断言

时间:2013-10-14 19:34:18

标签: soapui

我需要使用Java和SoapUI API以编程方式创建SoapUI测试套件和测试用例。我能够创建SoapUI项目并将WSDL导入到该项目中,但是我在理解用于创建测试套件,测试用例,测试步骤和断言的类时遇到了问题。我已经阅读了SoapUI API Javadoc,但是我是否有示例代码片段和/或文档,我可以用它来了解我将使用哪些类以及如何使用这些类?

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

我会尝试从这个http://www.soapui.org/Developers-Corner/integrating-with-soapui.html开始。但说实话,我不得不说我只使用了SoapUI GUI。