You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:编写SoapUI Groovy脚本实现测试套件串行执行与完成监控

Solution to Run SoapUI Test Suites Sequentially with Parallel Test Cases Inside Each Suite

Got it, let's work through your SoapUI scenario. You need to run 4 test suites one at a time, let test cases within each suite run in parallel, and add proper monitoring for when each full suite finishes (since the built-in tooling only tracks individual test cases). Here's a complete Groovy script that builds on your existing code, with all the functionality you need:

import java.util.concurrent.CountDownLatch
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunListener

// Get all test suites in the project (adjust if you need to target only specific 4)
def testSuites = context.testCase.project.getTestSuiteList()
log.info("Found ${testSuites.size()} test suites to run sequentially")

// Iterate through each test suite, run one at a time
testSuites.each { testSuite ->
    log.info("Starting execution of test suite: *${testSuite.name}*")
    
    // Enable parallel execution for test cases inside this suite
    testSuite.setTestCaseRunParallel(true)
    
    // CountDownLatch to track when all test cases in the suite finish
    def testCaseCount = testSuite.getTestCaseList().size()
    def suiteCompletionLatch = new CountDownLatch(testCaseCount)
    
    // Add a listener to each test case to update the latch when done
    def testCaseListener = new WsdlTestCaseRunListener() {
        @Override
        void afterRun(WsdlTestCaseRunner testCaseRunner, com.eviware.soapui.model.testsuite.TestRunContext runContext) {
            suiteCompletionLatch.countDown()
            log.info("Test case *${testCaseRunner.testCase.name}* completed. Remaining test cases in suite: ${suiteCompletionLatch.count}")
        }
    }
    
    // Register the listener with the test suite
    testSuite.addTestRunListener(testCaseListener)
    
    // Start running all test cases in the suite (they'll run in parallel)
    testSuite.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)
    
    // Wait until all test cases in the current suite finish before moving to the next
    suiteCompletionLatch.await()
    log.info("✅ Test suite *${testSuite.name}* has completed all test cases")
    
    // Remove the listener to avoid memory leaks
    testSuite.removeTestRunListener(testCaseListener)
}

log.info("All test suites have finished execution successfully!")

Key Details Explained:

  • Targeting Test Suites: The script fetches all test suites in your project – if you only want to run specific 4, add a filter like testSuites.findAll { it.name in ["Suite1", "Suite2", "Suite3", "Suite4"] } instead of using the full list.
  • Parallel Test Case Setup: testSuite.setTestCaseRunParallel(true) turns on parallel execution for test cases within each suite, which matches your requirement.
  • Suite Completion Monitoring: The CountDownLatch acts as a wait mechanism – we initialize it with the number of test cases in the suite, and each time a test case finishes, we decrement the latch. The script waits at suiteCompletionLatch.await() until all test cases are done, ensuring we only move to the next suite when the current one is fully complete.
  • Cleanup: We remove the test case listener after each suite to prevent unnecessary memory usage.

How to Use:

  1. Create a new "Controller" test case in your SoapUI project (keep it separate from your 4 target test suites).
  2. Add a Groovy Test Step to this controller test case.
  3. Paste the script above into the test step.
  4. Run the controller test case – it will handle the sequential suite execution with parallel test cases, and log clear status updates for each suite's completion.

内容的提问来源于stack exchange,提问作者Rock Star

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:44:08