我将如何 mock Person?
class Test {
private Person person;
...
public void testMethod() {
person.someMethod();
...
}
}
最佳答案
一种模拟 Person
的方法,使用注释和 mockito
:
public class UnitTest {
@Mock
private Person person;
@InjectMocks
private Test test = new Test();
@Test
public void testMethod() {
MockitoAnnotations.initMocks(this);
test.testMethod();
}
}
关于unit-testing - 如何模拟已声明的私有(private)字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53635511/