如何从Java运行soapUI测试 [英] How to run soapUI tests from Java

查看:283
本文介绍了如何从Java运行soapUI测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过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).

我还发现只有一个链接适用于我的项目 - http: //pritikaur23.wordpress.com/2013/06/16/saving-a-soapui-project-and-sending-requests-using-soapui-api/

I also found only one link which can be applicable for my project - http://pritikaur23.wordpress.com/2013/06/16/saving-a-soapui-project-and-sending-requests-using-soapui-api/ .

但是当我尝试做同样的事情时我遇到了以下错误 -

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;

这很奇怪,因为我添加了所有需要的jar文件。我甚至尝试过不同版本的xmlbeans。

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

提前感谢。

推荐答案

我找到了如何通过代码运行soapUI测试的方法。

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

小解释:

首先 - 我创建了一个maven项目,并将依赖项添加到pom.xml而不是包含.jar直接。对于SoapUI,需要添加以下依赖项:

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:

    <dependency>
        <groupId>com.github.redfish4ktc.soapui</groupId>
        <artifactId>maven-soapui-extension-plugin</artifactId>
        <version>4.6.4.0</version>
    </dependency>

其次 - 我还添加了一些依赖项,因为我有例外

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

java.lang.NoSuchMethodError

所需的依赖项:

    <dependency>
        <groupId>net.java.dev.jgoodies</groupId>
        <artifactId>looks</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>net.sf.squirrel-sql.thirdparty-non-maven</groupId>
        <artifactId>com-fifesoft-rsyntaxtextarea</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.karaf.eik.plugins</groupId>
        <artifactId>org.apache.commons.collections</artifactId>
        <version>3.2.1</version>
    </dependency>






在准备环境之后,我能够写一个代码。我向您展示了一个代码示例,该代码能够通过Java在指定的soapUI项目中运行所有测试套件和测试用例。


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<TestSuite> suiteList = new ArrayList<TestSuite>();
    List<TestCase> caseList = new ArrayList<TestCase>();

    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);
}

输出:

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.

这篇关于如何从Java运行soapUI测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆