简体   繁体   English

我需要测试吗?

[英]Do I need to test this?

I'm writing some unit tests for my MVC application but I have some trouble about common sense. 我正在为我的MVC应用程序编写一些单元测试,但是我在常识方面遇到了一些麻烦。

So, I have a function in my model to test called add_Member. 因此,我的模型中有一个要测试的函数称为add_Member。 I'm using CodeIgniter that turns empty inputs ($_POST) to 0. In mysql , 0 values are not considered as NULL values so the constraint NOT NULL on my column (ME_Email in this example) can't be applied. 我正在使用将空输入($_POST)为0的CodeIgnitermysql ,0值不视为NULL值,因此无法应用列上的约束NOT NULL(在此示例中为ME_Email)。

In my controller, I'm checking if my field $_POST['email'] is not empty and if it's a valid email. 在我的控制器中,我正在检查我的字段$_POST['email']是否不为空,以及是否为有效电子邮件。 I do that before calling my add_Member function from my model. 我先从模型中调用add_Member函数,然后执行此操作。

My question is, do I need to test an empty post value in my add_Member ? 我的问题是,我是否需要在add_Member中测试一个空的post值?

Thanks for answers 谢谢答案

It's a good practice to test all the methods in your app. 最好测试应用中的所有方法。 If you are gonna make any refactoring later, this will help you or if you deside just to extend this functionality in other classes. 如果您以后要进行任何重构,这将对您有所帮助,或者如果您只是想在其他类中扩展此功能,则将有帮助。 Also, this test can help you in the debbing process. 另外,此测试可以帮助您进行辩论。 My kind advice is to try to test all methods and functionalities. 我的建议是尝试测试所有方法和功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM