0

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.

2
  • Have you tried writing tests the same way as those generated by JHipster using @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 existing src/test/resources/config/application.yml Sep 1 at 14:33
  • Hi , I am trying the 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?
    – Shivani
    Sep 21 at 11:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.