[Livro Spock Framework] - Capítulo 12

Olá, fazendo o exemplo do capítulo 12 que trata de testes em aplicações rodando com spring-boot estou recebendo o seguinte erro ao executar:

Description:

Field em in com.example.groovyspring.LutadorService required a bean of type ‘javax.persistence.EntityManager’ that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type ‘javax.persistence.EntityManager’ in your configuration.

@Service
public class LutadorService {

@Autowired
private EntityManager em;
public	Lutador	findMelhorLutador() {
    return	(Lutador)	this.em.createQuery(
            "from	Lutador	order by vitorias desc,	nocontest asc, derrotasasc")
                    .setMaxResults(1)
                    .getSingleResult();
}
}

Poderia postar o código de sua classe de testes, por favor?

Recebi esse erro no momento que executei o projeto (SpringApplication.run). Ainda não escrevi a classe de teste

Então, para que a execução normal, sem ser a de testes, funcione, precisa de várias outras configurações de um projeto Spring.

No teste pode funcionar se criar Mocks de EntityManager, das repository etc.

A legal. Muito obrigado

Gerei a classe de teste do Controller porém ao executar ele também não consegue injetar o Controller e da o erro

Cannot invoke method getLutadores() on null object

Não conseguiria testar a não ser que mocke tudo , certo? Até o controller?
Como em um cenário real estaríamos testando um aplicação springboot rodando normalmente então
o ideal seria criar um aplicação com springboot para conseguir testar os exemplos do livro?

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.context.SpringBootTest
import spock.lang.Specification
import spock.lang.Stepwise

@SpringBootTest(classes = GroovySpringApplication)
@Stepwise
class LutadorControllerSpec extends Specification {
    @Autowired
    LutadorController controller
    @Autowired
    LutadorRepository repository
    @Autowired
    LutadorService service
    @Value('${msg.erro.cadastro}')
    private String msgErroCadastro;

    def 'deve retornarstatus 204 esem corpo	quando	não	existirem lutadores'() {
        when:
        def resposta = controller.getLutadores()
        then:
        resposta.statusCode == HttpStatus.NO_CONTENT
        !resposta.body
    }

}