Erlang/Elixir 向 Elixir 学习测试

chenge · December 26, 2020 · Last by xinyuewaisong replied at January 02, 2021 · 451 hits

看了yiming 做的 elixir 测试演示,感觉 rails 可以学习这个做法。

1 单元测试,避开数据库和 rails 测试

举例如下,测试 prepare,不测试 create。这样测试会非常快。

另外可以学习显式验证,避免使用 rails 的验证和 hook(after_save)

def create
   post = prepare_post()
   post.save
end

def prepare_post
  post = Post.new
  #显式验证
  must_string post.title

  post
end

2 集成测试

上线前可以做一次,写代码或者手工测试。

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.