0

Currently a colleague is arguing that

My test written as below:

@SpringBootTest(classes = App.class)
public class ServiceTest {

    private Integer a;
    private String str;


    @Before
    public void prepareTestData() {
       //
    }

    @Test
    public void test_scenario_1() {
        //
    } 
}

is not a unit test for my Service class because I am pulling through all the application using

@SpringBootTest(classes = App.class)

I understand that unit tests should be testing the service code in complete isolation, but I am not having a autowire service depdency injection of any sort in my test code.

My question is what is the @SpringBootTest(classes = App.class) annotation doing behind the scenes is it really bootstraping the complete application before the test code is run?

Is the test above really an integration test?

Anirudh
  • 2,286
  • 4
  • 38
  • 64
  • 3
    yes `@SpringBootTest` will load the application context. If you want unit testing for service layer you use `SpringRunner` https://stackoverflow.com/questions/58901288/springrunner-vs-springboottest – Ryuzaki L Jan 19 '20 at 18:34
  • Hum nice, so actually for my test I don't need the SpringBootTest annotation at all? – Anirudh Jan 19 '20 at 18:36
  • 1
    For unit testing you don't need it, But for integration testing `@SpringBootTest` is needed – Ryuzaki L Jan 19 '20 at 18:42
  • if you want to test the services only, use a mocking framework – Devilluminati Jan 19 '20 at 19:49

0 Answers0