简体   繁体   English

我应该测试用户注册的内容?

[英]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. 这些是我通常会为其编写测试的东西。

  • Business requirements. 业务需求。 The business have asked for these so you better make damn sure they work. 企业已经要求这些,所以你最好确定他们的工作。
  • Normal flow/usage. 正常流量/使用量。 General tests that prove it behaves how you want it to. 通用测试证明它的行为符合您的要求。
  • Edge cases. 边缘情况。 They may not happen very often but cover it with a test. 它们可能不会经常发生,但会通过测试覆盖它。
  • Bugs. 错误。 Need to prove that bad boy is history. 需要证明坏男孩是历史。
  • Bacon. 培根。 Always test for Bacon. 总是测试培根。

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

相关问题 我应该如何在asp.net MVC5 EF6中用3种不同的用户类型编码注册? - How should I code registration with 3 different user types in asp.net MVC5 EF6? 使用Automapper映射ViewModel之后我应该测试什么? - After using Automapper to map a ViewModel how and what should I test? ASP.NET MVC 4单元测试(我应该测试什么) - ASP.NET MVC 4 Unit testing (what i should test) 如何测试数据交换格式以及应使用哪种指标进行评估? - How can I test data exchange formats and what kind of metrics should I use to evaluate them? 我应该在ASP.NET MVC3项目中进行单元测试? - What should I unit test in my ASP.NET MVC3 project? 如果数据库中没有记录,并且我想向用户表明这一事实,我应该从Controller返回什么? - What should I return from Controller if there is no records in database, and I want to indicate this fact to the user? AspNet.Identity 自定义用户和自定义角色应该很简单; 我错过了什么? - AspNet.Identity Custom User and Custom Role should be simple; what am I missing? 我如何通过短信确认新的用户注册? - How could I confirm a new user registration via SMS? 我应该使用什么活动? - What event should I use? 分析这种用户注册方法 - Analyze this user registration approach
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM