【发布时间】:2021-09-06 13:00:24
【问题描述】:
我有这门课:
@Repository
public interface EnfantRepository extends JpaRepository<Enfant, Long> {
..
}
还有这项服务:
@Transactional
@Service
@Slf4j
public class EnfantService implements IEnfantService {
public Enfant save (Enfant enfant) {
return enfantRepository.save(enfant);
}
}
还有这个测试:
@RunWith(MockitoJUnitRunner.class)
public class EnfantServiceTest {
@Mock
private EnfantRepository enfantRepository = mock(EnfantRepository.class);
@InjectMocks
private EnfantService enfantService;
@Test
public void testSave() {
System.out.println(enfantService.save(Enfant.builder().build()));
Assertions.assertThat
(enfantService.save(Enfant.builder().build())).isNotNull();
}
}
但保存后返回null,测试失败
【问题讨论】:
标签: java spring junit mockito eclipselink