[英]What should I test for user registration?
Currently working on an MVC application, which has a registration form with some 12-14 fields that the user will have to fill in in order to register to our site. 目前正在开发MVC应用程序,该应用程序具有注册表单,其中包含12-14个字段,用户必须填写这些字段才能注册到我们的站点。 There are two requirements about the user input, and those are, surprisingly, that he provides a unique email and a unique username, ones that still don't exist in our database.
关于用户输入有两个要求,令人惊讶的是,他提供了一个唯一的电子邮件和一个唯一的用户名,这些用户名在我们的数据库中仍然不存在。 I already have tests about those validations, and the rest of the user input correctness is left to validation notations in the model, like the date format and the password strength requirements and so on, like this:.
我已经对这些验证进行了测试,其余的用户输入正确性留给了模型中的验证符号,比如日期格式和密码强度要求等,如下所示:
[Required(ErrorMessage = "Your password is required")]
[StringLength(20, MinimumLength = 8, ErrorMessage = "Must be between 8 and 20 characters")]
[RegularExpression(@"(?=^.{8,}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s)[0-9a-zA-Z!@#$%^&*()]*$", ErrorMessage = "Needs to have lowercase, uppercase and a number")]
[Display(Name = "Password")]
public string Password { get; set; }
Without testing these notations, I guess the only test I need to write about this logic are those about validating username and email uniqueness and adding a record to the db, which I already have, but I fear that only 3 tests might be too little. 在没有测试这些符号的情况下,我想我需要写的关于这个逻辑的唯一测试是关于验证用户名和电子邮件唯一性以及向db添加记录的那些,我已经拥有,但我担心只有3个测试可能太少。 Although I think (and hope, honestly) that I don't need tests for the out-of-the-box notation validations, I would like to hear that from someone more experienced and less lazy :) Also, if you could point out some general rules about what else should be tested when a user is registering, it would be great.
虽然我认为(并且希望,老实说)我不需要对开箱即用的符号验证进行测试,但我希望从更有经验且不那么懒惰的人那里听到:)同样,如果你能指出的话关于用户注册时应该测试什么的一些一般规则,这将是很好的。
If you someday decide to override the RegularExpression
class you would know if your tests fail. 如果有一天你决定覆盖
RegularExpression
类,你会知道你的测试是否失败。 Up to you to decide where to draw the line. 由您决定在哪里画线。 I would say its a small effort.
我会说这是一个小小的努力。
Firstly, don't write unit tests just for the sake of writing them. 首先,不要仅仅为了编写单元测试而编写单元测试。 More often than not they end up not being useful and not really proving anything.
通常情况下,他们最终没有用处,也没有真正证明什么。
These are the things that I would generally write tests for. 这些是我通常会为其编写测试的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.