简体   繁体   中英

Do I need to test this?

I'm writing some unit tests for my MVC application but I have some trouble about common sense.

So, I have a function in my model to test called 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.

In my controller, I'm checking if my field $_POST['email'] is not empty and if it's a valid email. I do that before calling my add_Member function from my model.

My question is, do I need to test an empty post value in my add_Member ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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