Testing 我如何正确地为一个计算有多少e';是在一条绳子里吗?

Testing 我如何正确地为一个计算有多少e';是在一条绳子里吗?,testing,junit,undefined,Testing,Junit,Undefined,下面是我定义的方法,它应该接受字符串作为输入,并返回字符“e”作为int出现的次数: public int count_e(String input){ int count = 0; for (int i = 0;i<input.length();i++){ char e = 'e'; if (input.charAt(i)==e){ count=count+1; i++;

下面是我定义的方法,它应该接受字符串作为输入,并返回字符“e”作为int出现的次数:

public int count_e(String input){
    int count = 0;
    for (int i = 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;
}
}

您未能将任何内容传递给您的
计数方法

比如说:

@Test
public void testCount_e() {
    String input = "Isabelle";
    int expected = 2;
    int actual = count_e(input);
    Assert.assertEqual("There are this many e's in the String.", expected, actual);
}
对于单元测试,您可能会将其缩短为:

@Test
public void testCount_e() {
    Assert.assertEqual("There are this many e's in the String.", count_e("Isabelle"), 2);
}
@Test
public void testCount_e() {
    Assert.assertEqual("There are this many e's in the String.", count_e("Isabelle"), 2);
}