我是 Elixir/Phoenix 的新手,所以我不确定这是否按预期工作或我应该解决的问题。
我有一个 Phoenix 应用程序,我刚刚开始添加集成测试。经过几天的设置和测试用户注册功能,我现在开始测试登录。
我正在使用小袋鼠:
测试.exs:
config :happy_app, :sql_sandbox, true
config :wallaby,
driver: Wallaby.Experimental.Chrome,
chrome: [headless: true],
screenshot_on_failure: true
test_helper.exs:
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(HappyApp.Repo, :manual)
{:ok, _} = Application.ensure_all_started(:wallaby)
Application.put_env(:wallaby, :base_url, HappyAppWeb.Endpoint.url())
我的测试如下所示:
defmodule HappyAppWeb.UserLoginTest do
use HappyAppWeb.IntegrationCase, async: true
alias HappyApp.Accounts
import HappyAppWeb.IntegrationSteps
@tag integration: true
test "user can login", %{session: session} do
email = "test-user@example.com"
password = "12345678"
# seed user into db
user = Accounts.create_user(%{email: email, password: password})
IO.inspect user
# logging in with the user's email and password
# asserting the view is correct
end
end
当我检查用户时:IO.inspect user
我得到:
IO.inspect user
=>
{:ok,
%HappyApp.Accounts.User{
__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
email: "test-user@example.com",
id: 449,
inserted_at: ~N[2019-11-24 13:20:33],
password: nil,
password_hash: "shhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
updated_at: ~N[2019-11-24 13:20:33]
}}
注意id: 449,
. 那是对的吗?测试之间不应该重置回1吗?
手动查看 postgres 我发现 happy_app_test 数据库确实是空的。数据在别处吗?