我正在使用Mockito来编写我的测试用例.我有一个简单的类,其中包含一个countPerson(boolean)我有兴趣测试的函数:
public class School {
//School is a singleton class.
public void countPerson(boolean includeTeacher) {
if (includeTeacher) {
countIncludeTeacher();
return;
}
countOnlyStudents();
}
public void countIncludeTeacher() {...}
public void countOnlyStudents() {...}
}
Run Code Online (Sandbox Code Playgroud)
在我的单元测试中,我想测试一下这个countPerson(boolean)函数:
public class SchoolTest{
private School mSchool;
@Before
public void setUp(){
mSchool = School.getInstance();
}
@Test
public void testCountPerson() {
mSchool.countPerson(true);
//How to test/verify countIncludeTeacher() is invoked once?
}
}
Run Code Online (Sandbox Code Playgroud)
countIncludeTeacher()在我的测试用例中,如何使用Mockito进行检查/验证一次?