SOAPUI: - 比较两个不同测试用例的断言

时间:2016-02-25 12:40:41

标签: soapui

我在两个不同的测试步骤中添加了Assertion。 每个断言都给了我节点数。

例如: -

Assertion 1:- Give count of nodes from JDBC test step
Assertion 2:- Give count of nodes from JSON response test step

我如何比较这两个断言?

1 个答案:

答案 0 :(得分:0)

可以使用包含断言的groovy script来完成。如果我理解正确,你可以将测试重新设计成一个案例,这样就不会依赖其他测试,即每个测试都应该是独立的。

假设案例 - 具有以下步骤的测试案例

  1. step1 - 属于Jdbc Test Step
  2. 类型
  3. step2 - 属于Rest Test Step
  4. 类型
  5. step3 - 属于Groovy Script Test Step
  6. 类型

    以下是第3步中的sudo代码:

    • 获取step1的响应并执行您想要对该响应执行的任何过程。由于您提到了节点计数,请将节点计数在变量中,例如jdbcNodeCount
    • 同样,对step2执行相同的操作,并将节点计入另一个变量,例如jsonNodeCount
    • 可以很容易地比较两个变量。

    如何在groovy步骤中获得其他步骤的响应?你走了:

    //You may rename step1, step2 as needed to your environment
    
    //initializing count variables
    def jdbcNodeCount = 0
    def jsonNodeCount = 0
    //Get step1 response
    def jdbcResponse = context.expand('${step1#Response}')
    log.info jdbcResponse
    //process jdbcResponse and assign jdbcNodeCount, add needed steps 
    
    //also add additional the assertions required for jdbcResponse here, so that you would not need Assertion 1 that you had already
    
    //Similarly get step2 response
    def jsonResponse = context.expand('${step2#Response}')
    log.info jsonResponse
    //process jsonResponse and assign jsonNodeCount, add needed steps
    
    //also add additional the assertions required for jsonResponse here, so that you would not need Assertion 2 that you had already
    
    //compare now
    assert jsonNodeCount == jdbcNodeCount, "Node counts are not matching"