【发布时间】:2020-07-31 10:20:52
【问题描述】:
我正在使用spring工具套件编写代码。有4层restContoller,buisnesslogic,domain,service.... 我想测试一个业务逻辑层的方法,它调用一个dao的方法,最后调用一个服务层的方法来返回一个简单的原始值......为了在业务逻辑类中明确,我有自动装配的域类,并且在域类中,我已经自动连接了服务类..当我运行测试类时我面临的问题是 NullPointerException 我正在附加测试类的代码……如果可能,请提供帮助
@ExtendWith(MockitoExtension.class)
class CustomerBlTest {
@Mock
CustomerService mockService;
@Autowired
CustomerDO customerDo;
@Autowired
@InjectMocks
CustomerBl bl; //buisnesslogic class
@Test
void checkForGetInteger() {
when(mockService.getIntegerFfromService()).thenReturn(3);
int actual = bl.getInteger();
Assertions.assertEquals(3, actual);
}
}
【问题讨论】:
标签: spring-boot testing junit mockito spring-mvc-test