Getting this error while writing test case in Jhipster springboot version: 2.7.3
@DataJpaTest
@AutoConfigureTestDatabase()
@TestPropertySource(locations = "classpath:config/application-testdev.yml")
class RoleRepositoryTest {
@Autowired
private RoleRepository roleRepository;
@Test
void setRoleRepositoryTest() {
}
@Test
void setRoleRepositoryFalse() {
//given
System.out.println("In given ");
Role role = new Role("Parent","string",true,"1601", ACTIVE,"string",false);
System.out.println("Before when");
//when
Role saved = roleRepository.save(role);
System.out.println("After when and before then");
//then
assertThat(roleRepository.findById(role.getId()).get()).isEqualTo(role);
assertThat(role).isNotNull();
assertThat(roleRepository.findAll().size()).isEqualTo(1);
}
}
This is my test class.
Getting this error
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
I have tried using different test annotations. Though this same code is working in Simple springboot project but not in jhipster.
Please help me with this.
Thanks.
@IntegrationTest
? It's a composite annotation for integration tests. that sets up all you need. Also, you don't need to use another application-testdev.yml, just use the existingsrc/test/resources/config/application.yml
unit testing
of respository. Same way I am able to do in springboot project but in jhipster it is giving error in datasource bean. Then I tried to define the database in application.yml(test) file then getting this error. Can you help me with this?