是否应该在 Rails 中测试本机验证?

编程入门 行业动态 更新时间:2024-10-25 01:23:16
本文介绍了是否应该在 Rails 中测试本机验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

每个人都知道自动化测试是一件好事.

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 中测试本机验证?

本文发布于:2023-11-14 02:56:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586026.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:本机   测试   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!