Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

C#
#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
Posted
Updated 22-May-11 7:09am
v5
Comments
Sergey Alexandrovich Kryukov 22-May-11 13:33pm    
If you already know you tests are "completely wrong", what's the problem?
--SA
Hari Gillala 22-May-11 13:59pm    
I don't know, what is the way to write the Unit test for the method. So I have done, what I could do, but I am asking an expert to help in writing what is the correct method to write.

1 solution

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()]


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900