每个人都知道自动化测试是一件好事.
Everybody knows that automated testing is a good thing.
并不是每个人都确切地知道要测试什么.
Not everybody knows exacly what to test.
我的问题是是否应该在应用程序中测试诸如 validate_presence_of、validate_uniqueness_of 等原生验证.
My question is if native validations like validate_presence_of, validate_uniqueness_of and so on should be tested in the application.
在我的办公室里,我们三个人,一个认为应该进行测试,一个认为不应该进行测试,而我对此犹豫不决.
In my office we are three, one thinks it should be tested, one thinks it shouldn´t and I am up in the air.
推荐答案是.
测试模型属性是否存在只是将 validates_presence_of 代码测试为实际测试的副产品,即 validates_presence_of 存在于您的模型中.
Testing that a model attribute is present or not is only testing the validates_presence_of code as a by-product of the real test which is that the validates_presence_of exists within your model.
如果有人注释掉一堆验证代码,然后忘记取消注释,那么这将不会被发现并可能导致各种问题.
If someone commented out a bunch of validation code and then forgot to uncomment it then this would go undetected and could cause all sorts of problems.
我测试它们,不是因为我认为它们不起作用,而是为了确保它们在需要时出现在我的模型中.
I test them, not because I think they don't work but to ensure that they are present in my model when required.
更多推荐
是否应该在 Rails 中测试本机验证?
发布评论