在C#.NET中进行单元测试. [英] Unit Test in C#.NET.
问题描述
我有一个简单的方法,该方法将字符串作为参数(domainname//firstname.lastname)并取出(domainname//)并仅作为firstname.lastname返回字符串.
我需要对以下情况进行单元测试.
检查单个斜杠(域名/名字.姓氏)
检查空字符串
检查空值
检查字符串是否包含////
我写了以下内容,但对我来说没有任何意义,因为这完全是错误的.
Hi I have a simple method, where It takes a string as parameter (domainname//firstname.lastname) and takes out (domainname//) and returns string as just firstname.lastname.
I need to unit test for the following case.
check for single slash (domainname/firstname.lastname)
Check for empty string
Check for null value
Check wheather the string contains // or not
I wrote the following but it does not make any sense to me, coz this is completely wrong.
#region Checking for null value
[TestMethod()]
public void CheckForNullValueTest()
{
string expected = "";
string source = @"domainname//hari.gillala";
string actual = Function.RemoveSlash(source);
assert.Equal(expected, actual);
}
#endregion
#region Checking for empty
[TestMethod()]
public void CheckForEmptyValueTest()
{
string expected = string.empty;
string source = @"domainname//hari.gillala";
string actual = Function.RemoveSlash(source);
assert.Equal(expected, actual);
}
#endregion
#region Checking for singleslash
[TestMethod()]
public void CheckForSingleSlashTest()
{
string expected = @"domainname/hari.gillala";
string source = "domainname//hari.gillala";
string actual = Function.RemoveSlash(source);
assert.Equal(expected, actual);
}
#endregion
#region Checking for Doubleslash
[TestMethod()]
public void CheckForDoubleSlashTest()
{
string expected = @"domainname//hari.gillala";
string source = "domainname//hari.gillala";
string actual = Function.RemoveSlash(source);
assert.Equal(expected, actual);
}
#endregion
谁能纠正我,哪里我错了.并帮助我为该功能的所有情况编写单元测试.
谢谢
Could any one correct me, where I am wrong. And help me to write the unit test for all the cases for the function.
Thank you
推荐答案
在您的代码中,您具有3个独立的函数,均称为"CheckForEmptyValueTest".这是拼写错误,还是您需要重命名其中的第2和第3个.
您在哪里:
In your code you have 3 separate functions all called ''CheckForEmptyValueTest''. Either this is a typo or you need to rename the 2nd and 3rd of them.
Where you have:
[TestMethod]
您需要:
you need:
[TestMethod()]
这些链接可能也有帮助:
http://msdn.microsoft.com/en-us/library/ms182517 (v = vs.80).aspx [ http://msdn.microsoft.com/en-us/library/ms182516 (v = VS.80).aspx [
These links may also help:
http://msdn.microsoft.com/en-us/library/ms182517(v=vs.80).aspx[^]
http://msdn.microsoft.com/en-us/library/ms182516(v=VS.80).aspx[^]
Hope this helps.
这篇关于在C#.NET中进行单元测试.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!