微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在开发一个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() {}
}

原文地址:https://www.jb51.cc/aspnet/247182.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐