如何创建空手道测试以验证WSDL文件

发布于 2025-02-12 03:38:16 字数 637 浏览 2 评论 0原文

我想确保我的WSDL合同没有变化,但是它对

  Scenario: Get demo.wsdl
    Given path '/demo'
    And param wsdl = 'demoLookup.wsdl'
    When method get
    Then status 200
    # note how we focus only on the relevant part of the payload and read expected XML from a file
    # And print 'response: ', response
    * def expected = read('expected-demo.wsdl')
    And match response contains expected

我收到

match failed: CONTAINS
  / | data types don't match (XML:LIST)
[60,119,115,100,108,58,100,101,10....

的文件的响应匹配,我假设这不是一个支持的功能,是否有任何解决方法,例如在RAW文件上匹配?

I'd like to ensure my WSDL contract is unchanged but matching on its response to a file

  Scenario: Get demo.wsdl
    Given path '/demo'
    And param wsdl = 'demoLookup.wsdl'
    When method get
    Then status 200
    # note how we focus only on the relevant part of the payload and read expected XML from a file
    # And print 'response: ', response
    * def expected = read('expected-demo.wsdl')
    And match response contains expected

I get

match failed: CONTAINS
  / | data types don't match (XML:LIST)
[60,119,115,100,108,58,100,101,10....

I'm assuming this is not a supported feature, is there any workarounds like matching on a raw file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不打扰别人 2025-02-19 03:38:16

空手道对WSDL文件没有直接的支持。我个人的看法是,出于API端到端测试的目的,您不需要它。只需获取示例XML有效载荷并进行比较即可。这就是大多数团队所做的。

我还要补充说,根据我的经验,团队正在寻找捷径,例如期望WSDL或某种“模式”为他们进行所有辛勤工作。这总是很糟糕。您需要测试数据库状态,业务逻辑等。只是我的2 c。

Karate has no direct support for WSDL files. My personal opinion is that for the purposes of API end-to-end testing, you don't need it. Just get a sample XML payload and do a comparison. This is what most teams do.

I'll also add that in my experience teams look for short-cuts, like expecting a WSDL or some kind of "schema" to do all the hard work of testing for them. This always ends badly. You need to test for things like database state, business logic and so on. Just my 2 c.

寄意 2025-02-19 03:38:16

如果其他人正在尝试类似的需求。

chksum.java

import org.springframework.util.StringUtils;
import java.util.zip.CRC32;

public class ChkSum {
    public static long generate(byte[] content){
        CRC32 crc32 = new CRC32();
        crc32.update(content, 0, content.length);
        return crc32.getValue();
    }

    public static int match(String expected, String actual){
        long exp_hash = generate(StringUtils.trimAllWhitespace(expected).getBytes());
        long act_hash = generate(StringUtils.trimAllWhitespace(actual).getBytes());

        return Long.compare(exp_hash,act_hash);
    }
}

功能

  Scenario: Get demo.wsdl
    * def chksum = Java.type('ChkSum')
    Given path '/demo'
    And param wsdl = 'demoLookup.wsdl'
    When method get
    Then status 200
    # note how we focus only on the relevant part of the payload and read expected XML from a file
    #And print 'response: ', response
    * xmlstring exp = read('expected-demo.wsdl')
    * xmlstring act = response
    * def result = chksum.match(exp, act)
    # And match exp == act
    And match result == 0

In case someone else is attempting a similar need.

ChkSum.java

import org.springframework.util.StringUtils;
import java.util.zip.CRC32;

public class ChkSum {
    public static long generate(byte[] content){
        CRC32 crc32 = new CRC32();
        crc32.update(content, 0, content.length);
        return crc32.getValue();
    }

    public static int match(String expected, String actual){
        long exp_hash = generate(StringUtils.trimAllWhitespace(expected).getBytes());
        long act_hash = generate(StringUtils.trimAllWhitespace(actual).getBytes());

        return Long.compare(exp_hash,act_hash);
    }
}

Feature

  Scenario: Get demo.wsdl
    * def chksum = Java.type('ChkSum')
    Given path '/demo'
    And param wsdl = 'demoLookup.wsdl'
    When method get
    Then status 200
    # note how we focus only on the relevant part of the payload and read expected XML from a file
    #And print 'response: ', response
    * xmlstring exp = read('expected-demo.wsdl')
    * xmlstring act = response
    * def result = chksum.match(exp, act)
    # And match exp == act
    And match result == 0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文