我有一个服务:
@Service
@Transactional
@RequiredArgsConstructor
public class BookService {
private final BookRepository bookRepository;
public Book findOne(Long id) {
return bookRepository.findById(id).orElse(null);
}
public Book getOne(Long id) {
return bookRepository.findById(id)
.orElseThrow(() -> new BadRequestAlertException("entity-not-found", ("Entity with id: " + id + " not found!")));
}
public List<Book> getAll() {
return bookRepository.findAll();
}
public Book save(Book book) {
return bookRepository.save(book);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经为数据库(BookRepository)和控制器层(使用 BookService 的 BookController)编写了集成测试。我在任何地方都找不到服务层集成测试的示例。如果我正确编写单元测试,是否有为其编写集成测试的用例?据我所知(这不是规则,而是常见的用例):