Test cases to check if one string is present in another
I recently had this question in an interview to write test cases to test a function which checks if one string is 开发者_C百科present in another I didn't quite expect that question to pop in the interview for a developer position, yesterday I got the heads up for an on-site visit from same company I wanted to get some pointers from testing folks here to get an idea (before I head there) as to go about answering those type of questions. This is the skeleton they provided for the function to ask me to test it.
public static boolean checkSubString(String str1, String str2)
{
//first string is the source
// second string is the reference
if(str1.contains(str2))
return true;
else
return false;
}
Thanks for reading. I look forward to your replies eagerly.
Just one tip: consider this part: str1.contains(str2)
, when would it result in true
, when in false
and what would be needed to make it throw an Exception.
That would then be your test cases.
You'll need at least two test cases to check that the function works; one that you expect to pass and one that you expect to fail. Since you have access to (and understanding of) the code, you can construct at least one more test case; one you expect to throw an exception.
精彩评论