I recently had this question in an interview to write test cases to test a function which checks if one string is 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 intrue, when infalseand what would be needed to make it throw an Exception.That would then be your test cases.