0

以下属性测试工作正常,但是,我认为应该有更好、更有效的方法来实现它。

params下面property将是这样的:

%{
  "project_id" => "%&!XX!hLCfsS-dO_<fy?kpi4y=AEumQ$Xn:#.7Fl TnH~k>ZLB[q",
  "task_id" => [
    %{"asset_id" => 10, "tasks" => []},
    %{"asset_id" => 10, "tasks" => []}
  ]
}

性能测试:

property "bad project value" do
   [user, project] = prepare()
   user_gen = constant(%{id: user.id})

   project_gen =  constant("project_id")
                  |> map_of(Factory.my_terms, length: 1)

   tasks = constant(%{"asset_id" => 10, "tasks" => []})
          |> list_of(length: 2)
   tasks_gen = constant("task_id")
               |> map_of(tasks, length: 1)

   check all project <- project_gen, task <- tasks_gen , user <- user_gen do
     params = Map.merge(project, task)
     res = ProjectTask.Save.save(params, user)
     assert res == {:error, :not_found}
   end

Factory.my_terms如下:

def my_terms() do
  one_of([string(:alphanumeric), string(:ascii), atom(:alphanumeric), integer(), binary()])
end

更新

  property "bad project value" do
      [user, project] = prepare()
      project_gen =  constant("project_id")
                     |> map_of(Factory.my_terms, length: 1)
      tasks = List.duplicate(%{"asset_id" => 10, "tasks" => []}, 2)
      tasks = %{"tasks" => tasks}
      check all project <- project_gen do
        params = Map.merge(project, tasks)
        res = ProjectTask.Save.save(params, %{id: user.id})
        assert res == {:error, :not_found}
      end
    end
4

0 回答 0