初级 Web 开发人员和我的任务是为项目创建单元测试。
问问题
200 次
2 回答
0
据我了解,您要求检查您的代码是否符合要求?我不知道您的用户和用户提供者,但您还需要
改变
Assert.AreEqual(user.UserName, "test.user");
至
Assert.AreEqual("test.user", user.UserName.ToLower()); //EXPECTED, then ACTUAL
甚至更正确的方法:
StringAssert.AreEqualIgnoringCase("test.user", user.UserName);
此更改将满足您的原始要求:
//test by using the “.ToLower()” function on the resulting string.
//verify case doesn’t matter on username.
更多关于AreEqual
更多关于StringAssert
于 2013-05-08T18:08:40.337 回答
0
[TestMethod]
public void TestGetUser()//Shell Complete, test code needs review
{
try
{
//set test to get user
AsaMembershipProvider prov = this.GetMembershipProvider();
//call get user
MembershipUser user = prov.GetUser("test.user", false);
//ask for the username with deliberate case differences
MembershipUser user2 = prov.GetUser("TeSt.UsEr", false);
//prove that you still get the user,
Assert.AreNotEqual(null, user);
Assert.AreNotEqual(null, user2);
//test by using the “.ToLower()” function on the resulting string.
//verify case doesn’t matter on username.
Assert.AreEqual(user.UserName.ToLower(), user2.UserName.ToLower());
Assert.AreEqual(user.UserName.ToLower(), "test.user");
}
catch (Exception ex)
{
LogMessage(ex);
Assert.Fail(ex.Message);
}
}
于 2013-05-08T18:09:16.640 回答