【发布时间】:2016-05-05 14:19:12
【问题描述】:
我正在尝试将我的课程设置为在Junit 中使用。
但是,当我尝试执行以下操作时,出现错误。
当前测试类:
public class PersonServiceTest {
@Autowired
@InjectMocks
PersonService personService;
@Before
public void setUp() throws Exception
{
MockitoAnnotations.initMocks(this);
assertThat(PersonService, notNullValue());
}
//tests
错误:
org.mockito.exceptions.base.MockitoException:
Cannot instantiate @InjectMocks field named 'personService'
You haven't provided the instance at field declaration so I tried to construct the instance.
However the constructor or the initialization block threw an exception : null
我该如何解决这个问题?
【问题讨论】:
标签: java spring junit mockito autowired