mardi 3 novembre 2020

SpringBoot - Autowire not working in test

I'm trying to test a service like this:

@EnableAutoConfiguration
@ActiveProfiles("test")
@ContextConfiguration(classes = MyService.class)
@SpringBootTest()
public class ServiceTest {

    @Autowired
    MyService service;

    @Test
    public void test() {
        Response response = service.getDetails("TEST",
                "TEST",
                null, "1S");

        System.out.println(response);
    }
}

But the autowire doesn't work, I have a null pointer exception att the call of getDetails function.

What is wrong, how can I use my service in a test ?

Aucun commentaire:

Enregistrer un commentaire