Last active
October 17, 2023 14:05
-
-
Save alexaugustobr/8047ed47c34c061df81b8a0f80b76eb6 to your computer and use it in GitHub Desktop.
Classe base para testes do Spring Data JPA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.jupiter.api.extension.ExtendWith; | |
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | |
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | |
import org.springframework.test.annotation.DirtiesContext; | |
import org.springframework.test.context.ActiveProfiles; | |
import org.springframework.test.context.junit.jupiter.SpringExtension; | |
/* | |
Classe base para testes do Spring Data JPA | |
*/ | |
//Extensão do Spring faz com que Autowired funcione | |
@ExtendWith(SpringExtension.class) | |
//Cria todos os beans de Repository | |
@DataJpaTest | |
//Carrega profile test-jpa, é necessário ter tal arquivo configurado e na pasta test/resources | |
@ActiveProfiles("test-jpa") | |
//Força o DataJpaTest a não cria uma base de testes | |
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | |
//Limpa dados cadastrados durante os testes | |
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) | |
public abstract class DataJpaIT { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment