有没有更好的方法来引用子功能,以便完成此测试?

时间:2019-08-14 21:34:13

标签: karate

在运行以下方案时,测试将完成运行,但是执行之后会立即挂起,并且gradle test命令将永远不会完成。尚未生成黄瓜报告,因此该报告在该点之前挂起。

这似乎是由于对不同的场景进行了两次调用read()导致的,而这两个场景都调用了第三种场景。第三个场景引用父上下文来检查当前请求。 当该父请求存储在变量中时,测试将挂起。在离开第三个场景之前清除该变量后,测试将正常完成。因此,有关引用该上下文的某些操作会将测试挂到最后。

这有没有完成的原因?我是否缺少一些重要的代码来完成测试?

我在特殊请求方案的末尾添加了* def currentRequest = {},它可以完成测试,但这似乎很容易。

这是顶级测试方案:

  Scenario: Updates user id
      * def user = call read('utils.feature@endpoint=create-user')
      * set user.clientAccountId = user.accountNumber + '-test-client-account-id'
      * call read('utils.feature@endpoint=update-user') user
      * print 'the test is done!'

测试场景在同一个utls.feature文件中调用2个不同的场景

utils.feature:

  @ignore
  Feature: /users

  Background:
      * url baseUrl

  @endpoint=create-user
  Scenario: create a standard user for a test
    Given path '/create'
    * def restMethod = 'post'
    * call read('special-request.feature')
    When method restMethod
    Then status 201


  @endpoint=update-user
  Scenario: set a user's client account ID
    Given path '/update'
    * def restMethod = 'put'
    * call read('special-request.feature')
    When method restMethod
    Then status 201
    And match response == {"status":"Success", "message":"Update complete"}

这两种util方案都调用具有不同参数/请求的特殊请求功能。

special-request.feature:

  @ignore
  Feature: Builds a special

  Scenario: special-request
      # The next line causes the test to sit for a long time 
      * def currentRequest = karate.context.parentContext.getRequest() 
      # Without the below clear of currentRequest, the test never finishes
      # We are de-referencing the parent context's request allows test to finish
      * def currentRequest = {} 

没有currentRequest = {},这是我在测试似乎停止之前得到的最后一行输出。

12:21:38.816 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate - response time in milliseconds: 8.48
1 < 201
1 < Content-Type: application/json
{
  "status": "Success",
  "message": "Update complete"
}


12:21:38.817 [ForkJoinPool-1-worker-1] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $
12:21:38.817 [ForkJoinPool-1-worker-1] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $
12:21:38.817 [ForkJoinPool-1-worker-1] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $
12:21:38.817 [ForkJoinPool-1-worker-1] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $
12:21:38.818 [ForkJoinPool-1-worker-1] INFO com.intuit.karate - [print] the test is done!
12:21:38.818 [pool-1-thread-1] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $
<==========---> 81% EXECUTING [39s]

使用currentRequest = {},测试完成,并且黄瓜报告成功生成,这是我希望即使没有该行也会发生的情况。

1 个答案:

答案 0 :(得分:0)

两条评论:

LRESULT CPCSampleView::OnWindowSetSection(WPARAM  wParam, LPARAM  lParam)
{
    CPCSampleDoc *pDoc = GetDocument();

    CPoint  ptOrigin;
    ptOrigin = GetScrollPosition();

    wParam *= m_sizeCell.cy;    // multiple text line offset by height of each line of text
    ptOrigin.y = wParam;        // change the vertical position of the scroll bar

    ScrollToPosition(ptOrigin);   // move the scroll bar elevator

    this->UpdateWindow();     // tell view to update displayed window to match elevator position

    return 0;
}

哇,这些是内部API,不适合用户使用,我强烈建议改为将值作为变量传递。因此,如果您对此有疑问,所有的选择都将关闭。

听起来您上面确实有一个空指针(在这里没有惊奇)。

0.9.4中存在一个错误,该错误会在某些极端情况下导致测试失败,例如您在做的事情,测试前的生命周期或* karate.context.parentContext.getRequest() 中的挂起并行运行器失败。您应该在日志中看到表明失败的内容,如果不是这样的话-请尝试帮助我们复制此问题。

此问题应该在karate-config.js分支中解决,因此如果您可以从源代码进行构建并在本地进行测试,则可以为您提供帮助。说明在这里:https://github.com/intuit/karate/wiki/Developer-Guide

如果您仍然发现问题,请 执行此操作:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue