C# unit testing a class -


i'm doing unit testing class library , i'm stuck on how test method. need test scenarios check if password less 8 characters cannot accepted, check if password 8 or more characters can accepted , check if password space in front cannot accepted.

the code below class library.

public class passwordchecker {     public bool checkpassword(string pwd)     {         if (pwd.length >= 8 && !pwd.startswith(""))         {             return true;         }         else         {             return false;         } 

the code below testing project.

[testclass] public class passwordcheckertest  {     [testmethod]     public void checkpassword8charslong()     {         string validpassword = "12345678";         string invalidpassword = "abc";          passwordchecker checker = new passwordchecker();          assert.istrue(checker.checkpassword(validpassword));         assert.isfalse(checker.checkpassword(invalidpassword));      } 

probably error due pwd.startswith("") statement, looking @ test, there many tests in 1 test method, should split 3 methods,

    [testmethod]     public void givenvalidpassword_whencheckpassword_thenreturntrue(){          var password= "12345678";           var sut = new passwordchecker();          var result = sut.checkpassword(password);            assert.istrue(result );        }      [testmethod]     public void givenpasswordlessthan8characters_whencheckpassword_thenreturnfalse(){          var password= "1278";           var sut = new passwordchecker();          var result = sut.checkpassword(password);            assert.isfalse(result );        }      [testmethod]     public void givenpasswordstartwithspace_whencheckpassword_thenreturnfalse(){          var password= " 12345678";           var sut = new passwordchecker();          var result = sut.checkpassword(password);            assert.isfalse(result );        } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -