testing - How do I properly write out a JUnit test for a method that counts how many e's are in a string? -
here method have defined supposed accept string input , should return number of times char 'e' occurs int:
public int count_e(string input){ int count = 0; (int = 0;i<input.length();i++){ char e = 'e'; if (input.charat(i)==e){ count=count+1; i++; return count; } else{ count=count+1; i++; } } return count; }
}
i trying write junit test see if can input string method , return correct number of e's. below test, , @ moment keep getting error saying method count_e undefined type string.
can tell me why coming undefined?
@test public void testcount_e() { string input= "isabelle"; int expected= 2; int actual=input.count_e(); asserttrue("there many e's in string.",expected==actual); }
}
you failed pass anything count_e
method!
how like:
@test public void testcount_e() { string input = "isabelle"; int expected = 2; int actual = count_e(input); assert.assertequal("there many e's in string.", expected, actual); }
for unit test, shorten to:
@test public void testcount_e() { assert.assertequal("there many e's in string.", count_e("isabelle"), 2); }
Comments
Post a Comment