如何使用java从Soapui运行特定的TestSuite或TestCase?

时间:2015-02-06 19:21:36

标签: java soapui

我在soapui中创建项目后,现在我想从我的项目中运行特定的TestSuites和TestCases,在这里我找到了一个google的例子,但它执行了项目中的所有TestSuite。

如何指定我想要运行的TestSuite和TestCase的名称?

import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;

import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.model.support.PropertiesMap;
import com.eviware.soapui.model.testsuite.TestCase;
import com.eviware.soapui.model.testsuite.TestRunner;
import com.eviware.soapui.model.testsuite.TestRunner.Status;
import com.eviware.soapui.model.testsuite.TestSuite;

public class TestRunnerSample {

  @Test
  public void fullControl() throws Exception {

    WsdlProject project = new WsdlProject("C:/Folder/Project.xml");
    List<TestSuite> testSuites = project.getTestSuiteList();

    for( TestSuite suite : testSuites ) {
    List<TestCase> testCases = suite.getTestCaseList();

      for( TestCase testCase : testCases ) {
        System.out.println("Running SoapUI test [" + testCase.getName() + "]");
        TestRunner runner2 = testCase.run(new PropertiesMap(), false);
        assertEquals(Status.FINISHED, runner2.getStatus());
      }
    }
  }
}

1 个答案:

答案 0 :(得分:2)

查看com.eviware.soapui.impl.wsdl.WsdlProject API,有一个getTestSuiteByName(String testSuiteName)方法来获取TestSuite的名称,此方法返回一个com.eviware.soapui.impl.wsdl.WsdlTestSuite对象,该对象也有getTestCaseByName(String testCaseName)方法来获取TestSuite中的TestCase名称。

您可以使用com.eviware.soapui.impl.wsdl.WsdlTestSuite方法同时运行TestSuite(com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase)或特定的TestCase(run(StringToObjectMap properties, boolean async)),就像在代码示例中一样。

使用您的代码,您可以执行以下操作:

WsdlProject project = new WsdlProject("C:/Folder/Project.xml");
WsdlTestSuite ts = project.getTestSuiteByName('myTestSuite');
WsdlTestCase tc = ts.getTestCaseByName('myTestCase');

System.out.println("Running SoapUI test [" + tc.getName() + "]");
// run a specific testCase
TestRunner tcRunner = tc.run(new PropertiesMap(), false);
assertEquals(Status.FINISHED, tcRunner.getStatus());

// or alternatively run the whole TestSuite
TestRunner tsRunner = ts.run(new PropertiesMap(), false);
assertEquals(Status.FINISHED, tsRunner.getStatus());
...

希望这有帮助,