加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – ASP.net MVC RTM测试命名约定

发布时间:2020-12-16 04:05:43 所属栏目:asp.Net 来源:网络整理
导读:我正在开发一个asp.net mvc应用程序并编写我的单元测试BDD样式. 例如. GetResource_WhenResourceFileExists_ShouldReturnResources() 但是当我为我的控制器编写测试时,我通常有两个同名的方法.一个没有获取请求的参数,一个没有用于帖子.有没有人在这里有一个
我正在开发一个asp.net mvc应用程序并编写我的单元测试BDD样式.
例如.

GetResource_WhenResourceFileExists_ShouldReturnResources()

但是当我为我的控制器编写测试时,我通常有两个同名的方法.一个没有获取请求的参数,一个没有用于帖子.有没有人在这里有一个很好的命名约定来区分这两者?

我能想到:

1.
LogIn_WithParameters_ShouldReturnLogInView()
LogIn_WithoutParameters_WhenAuthenticationFailed_ShouldReturnLogInView()
LogIn_WithoutParameters_WhenAuthenticationPassed_ShouldReturnProfileRedirect()

2.
LogIn_Get_ShouldReturnLogInView()
LogIn_Post_WhenAuthenticationFailed_ShouldReturnLogInView()
LogIn_Post_WhenAuthenticationPassed_ShouldReturnProfileRedirect()

3.
LogIn_ShouldReturnLogInView()
LogIn_WhenCalledWithParametersAndAuthenticationFailed_ShouldReturnLogInView()
LogIn_WhenCalledWithParametersAndAuthenticationPassed_ShouldReturnProfileRedirect()

任何意见?

解决方法

我使用以下格式,对我来说效果非常好:
[TestFixture]    
public class Log_in_with_parameters_should
{
    [Test]
    public void Return_the_log_in_view() {}
}

[TestFixture]    
public class Log_in_without_parameters_should
{
    [Test]
    public void Return_the_log_in_view_when_the_authentication_failed() {}

    [Test]
    public void Redirect_to_the_profile_when_the_authentication_passed() {}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读