执行测试后的项目数量与预期数量不匹配

发布于 2024-12-09 03:36:32 字数 113 浏览 2 评论 0原文

我的数据库中已经存在一个用户(管理员)。我运行黄瓜测试并创建另一个用户。我期望在执行场景后有 2 个用户,但得到 1 个。我的错误在哪里?可能是黄瓜不计算数据库中的现有实体,如果它们不是通过黄瓜创建的......

I have an user (administrator) already existed in database. I run the cucumber test and create another user. I expected the 2 users after executing a scenario, but got 1. Where is my mistake? May be cucumber does not count an existing entities in db if they are not created via cucumber...

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

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

发布评论

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

评论(3

荒路情人 2024-12-16 03:36:32

每次测试前都会清除您的测试数据库。您必须创建管理员作为 Cucumber 步骤的一部分,可能使用“背景:”是最好的方法。

编辑 要以管理员身份登录,请执行以下操作:

Background:
  Given I am an admin
  And I have logged in

  Scenario: Create a user
    Given I go to the new user page
    And I fill in "email" with "[email protected]"
    And I submit the form
    Then there should be 2 users

希望您能够自己编写这些步骤定义。 “鉴于我是管理员”只会创建一个管理员用户,而“我已登录”将进入登录页面,以管理员身份登录。

Your test database is cleared before every test. You have to create the Admin as part of your Cucumber steps, probably with a "Background:" is the best way.

edit To log in as an admin, do something like this:

Background:
  Given I am an admin
  And I have logged in

  Scenario: Create a user
    Given I go to the new user page
    And I fill in "email" with "[email protected]"
    And I submit the form
    Then there should be 2 users

Hopefully you're able to write those step definitions yourself. "Given I am an admin" will just create an admin user, and "I have logged in" will go through the Login page, logging in as the admin.

别闹i 2024-12-16 03:36:32

这是我的代码:
在功能中:

Feature: "Manage Users"
  Background: I should sign in firstly
    Given I am have an administrator
    When I am on the login_page
    And I fill in "session_login" with "administrator"
    And I fill in "session_password" with "password"
    And I press "Sign In"
    Then I should see "You are logged in"

在步骤中:

Given /^I am have an administrator$/ do
  User.create!(:login => 'administrator', :locale => 'en', :password => 'password', :email => '[email protected]')
  User.find_by_login('administrator').should_not be nil
end

我无法登录。

This is my code:
In feature:

Feature: "Manage Users"
  Background: I should sign in firstly
    Given I am have an administrator
    When I am on the login_page
    And I fill in "session_login" with "administrator"
    And I fill in "session_password" with "password"
    And I press "Sign In"
    Then I should see "You are logged in"

in steps:

Given /^I am have an administrator$/ do
  User.create!(:login => 'administrator', :locale => 'en', :password => 'password', :email => '[email protected]')
  User.find_by_login('administrator').should_not be nil
end

And i cannot log in.

吐个泡泡 2024-12-16 03:36:32

固定的!
我将数据库策略从“事务”更改为“截断”。
线程已完成

Fixed!
I changed database policy from 'transaction' to 'truncation'.
Thread is finished

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文