soapui java,如何从Java运行soapUI测试

I need to run SoapUI test by Java. Could you please advise me useful links? And I would be happy if you can show me how to load/run tests (code examples).

But when I try to do the same I faced below errors -

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Ljava/lang/ClassLoader;Ljava/lang/String;)Lorg/apache/xmlbeans/SchemaTypeSystem;

It's weird because i added all needed jar files. Also I even tried different versions of a xmlbeans.

Thank in advance.

解决方案

I found the way how to run soapUI test by code.

The small explanation:

Firstly - I created a maven project and added dependencies to pom.xml instead of a including .jar directly. For the SoapUI tests was needed to add following dependencies:

com.github.redfish4ktc.soapui

maven-soapui-extension-plugin

4.6.4.0

Secondly - I also added a few dependencies because I got an exceptions

java.lang.NoSuchMethodError

The needed dependencies:

net.java.dev.jgoodies

looks

2.1.4

net.sf.squirrel-sql.thirdparty-non-maven

com-fifesoft-rsyntaxtextarea

1.0.0

org.apache.karaf.eik.plugins

org.apache.commons.collections

3.2.1

After preparing of the environment I was able to write a code. I show you an example of a code what able to run all test suites and test cases in a specified soapUI project by Java.

// method for running all Test Suites and test cases in the project

public static void getTestSuite() throws Exception {

String suiteName = "";

String reportStr = "";

// variables for getting duration

long startTime = 0;

long duration = 0;

TestRunner runner = null;

List suiteList = new ArrayList();

List caseList = new ArrayList();

SoapUI.setSoapUICore(new StandaloneSoapUICore(true));

// specified soapUI project

WsdlProject project = new WsdlProject("your-soapui-project.xml");

// get a list of all test suites on the project

suiteList = project.getTestSuiteList();

// you can use for each loop

for(int i = 0; i < suiteList.size(); i++){

// get name of the "i" element in the list of a test suites

suiteName = suiteList.get(i).getName();

reportStr = reportStr + "\nTest Suite: " + suiteName;

// get a list of all test cases on the "i"-test suite

caseList = suiteList.get(i).getTestCaseList();

for(int k = 0; k < caseList.size(); k++){

startTime = System.currentTimeMillis();

// run "k"-test case in the "i"-test suite

runner = project.getTestSuiteByName(suiteName).getTestCaseByName(caseList.get(k).getName()).run(new PropertiesMap(), false);

duration = System.currentTimeMillis() - startTime;

reportStr = reportStr + "\n\tTestCase: " + caseList.get(k).getName() + "\tStatus: " + runner.getStatus() + "\tReason: " + runner.getReason() + "\tDuration: " + duration;

}

}

// string of the results

System.out.println(reportStr);

}

Output:

Test Suite: TS_ONE

TestCase: TC_ONE Status: FAILED Reason: Cancelling due to failed test step Duration: 1549

TestCase: TC_TWO Status: FINISHED Reason: {} Duration: 1277

...

TestCase: TC_N Status: FAILED Reason: Cancelling due to failed test step Duration: 1282

Test Suite: TS_TWO

TestCase: TC_BlaBla Status: FINSHED Reason: {} Duration: 1280

...

I hope the information above will help someone.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值