我通常检查我的测试是否返回预期结果,如下所示:
company = company_fixture() # inserts a company in the database with default attributes
assert Profile.get_company!(company.id) == company
但这失败了
Assertion with == failed
code: assert Profile.get_company!(company.id) == company
left: %MyApp.Profile.Company{
customers: [],
employees: [],
# more attributes, all matching
}
right: %Databaum.Profile.Company{
customers: #Ecto.Association.NotLoaded<association :customers is not loaded>,
employees: #Ecto.Association.NotLoaded<association :employees is not loaded>,
# more attributes, all matching
}
推荐的处理方法是什么?我显然想避免在测试中预加载关联,因为这样可以避免检查它们没有预加载的事实Profile.get_company!/1
。