【发布时间】:2021-12-30 04:07:24
【问题描述】:
现在只有一个模拟工作正常。另一个返回空指针异常。 @Autowired 和 @Mock 都为 BCryptPasswordEncoder passwordEncoder 提供空指针;
我的测试课
@SpringBootTest
public class UserServiceTests {
@Autowired
BCryptPasswordEncoder passwordEncoder;
@Mock
private UserRepository userRepository;
@InjectMocks
private UserService userService =new UserServiceImpl();
@BeforeEach
void setUp() throws Exception{
MockitoAnnotations.initMocks(this);
}
}
我的实现类
【问题讨论】:
-
显示更多关于你的测试类配置,例如它是一个@SpringBootTest 还是一个简单的模拟测试等等
-
更新问题,立即查看
-
请勿发布代码图片。将代码添加到问题中。谢谢!
标签: spring-boot junit mocking mockito junit5