【问题标题】:How to use grpcurl with any automation framework?如何将 grpcurl 与任何自动化框架一起使用?
【发布时间】:2021-03-09 23:54:35
【问题描述】:

使用 grpcurl,我们可以与 gRPC 服务进行交互。但是,响应不会自动验证。有没有一种方法可以让我们使用带有任何自动化框架的 grpcurl 为 gRPC 服务编写测试用例?

【问题讨论】:

    标签: automation mocha.js grpc grpcurl


    【解决方案1】:

    自动化 grpcurl 可以使用 cypress 完成,如下所示:

    spec.js 文件

    it('verify grpc service response', function () {
            let path = './cypress/fixtures/test_data.json';
            let method = 'Service.Method';
            
            //calling custom cypress command
            cy.func(path, method).then((response) => {
                expect(response.val1).to.eq(0)
                expect(JSON.parse(response.stdout).val2).to.equal(1);
            })
        });
    

    常用方法—— cypress/support/commands.js

    Cypress.Commands.add("func", (filepath, method) => {
      cy.readFile(filepath).then((str) => {
        str = JSON.stringify(str)
        let response = cy.exec('npx grpcurl --plaintext -d \'' + str + '\' grpc.server.com:80 ' + method)
        return response;
      })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-09
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-01
      • 1970-01-01
      • 2011-10-08
      相关资源
      最近更新 更多