【问题标题】:How to run soapUI tests from Java如何从 Java 运行soapUI 测试
【发布时间】:2014-04-07 09:10:18
【问题描述】:

我需要通过 Java 运行 SoapUI 测试。你能告诉我有用的链接吗?如果您能告诉我如何加载/运行测试(代码示例),我会很高兴。

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

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

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

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

提前致谢。

【问题讨论】:

    标签: java soapui


    【解决方案1】:

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


    小解释:

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

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

    其次 - 我还添加了一些依赖项,因为我遇到了异常

    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 项目中运行所有测试套件和测试用例。

        // 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
        ...
    

    我希望以上信息对某人有所帮助。

    【讨论】:

    • 我想通过在运行时传递有效负载来测试 API,我将从某处获得。
    【解决方案2】:

    使用持续集成服务器(例如 Hudson 非常适合此),可以自动运行 JUnit 格式的单元测试。下面是在 JUnit 测试中集成 SoapUI 项目的示例。

    public void testRunner() throws Exception 
    {
        SoapUITestCaseRunner runner = new SoapUITestCaseRunner(); 
        runner.setProjectFile( "src/dist/sample-soapui-project.xml" );
        runner.run(); 
    }
    

    更多信息here

    【讨论】:

    • 感谢您的回答。我还在下面添加了我的解决方案的评论。
    • @HeLL 如果我使用这种方法,我将如何设置测试用例的属性。
    【解决方案3】:

    @HeLL 提供的代码仅需要当前的 SoapUI 依赖项

        <dependency>
            <groupId>com.smartbear.soapui</groupId>
            <artifactId>soapui</artifactId>
            <version>5.1.3</version>
            <scope>test</scope>
        </dependency>
    

    【讨论】:

    【解决方案4】:

    我遇到了同样的问题,但我使用以下方法解决了它:

    <dependency>
        <groupId>com.smartbear.soapui</groupId>
        <artifactId>soapui</artifactId>
        <version>4.6.1</version>
    </dependency>

    【讨论】:

      猜你喜欢
      • 2019-07-05
      • 2022-12-10
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多