Home > Mobile >  How to do integration testing with spring and junit by scanning classpath instead of manually specif
How to do integration testing with spring and junit by scanning classpath instead of manually specif

Time:10-28

I'm trying to do some sort of integration testing (not really full testing, only it's not really unit testing either) on a service :

package foo;


@Component
public class FooService {}

And the corresponding test :

package foo;

@SpringBootTest
public FooTest {
   @Autowired FooService fooService;
}

Only when I try to test it says

No qualifying bean of type 'foo.FooService' available

I could add the class to @SpringBootTest like this :

@SpringBootTest(classes = {FooService.class})

But I don't want to manually select the classes I want to test. My application is much larger than the MWE, and I want to test without having to specify each class I am testing and their respective dependencies.

Is there anyway to tell spring to scan and autowire dependencies like it would outside of tests ?

CodePudding user response:

add @Service annotaion to the FooService class

  • Related