15

I am very new to SpringBoot. I need to understand how to write an integration test using SpringBoot. I have seen some examples on the Internet which use the @IntegrationTest annotation whereas some other examples which use the @SpringBootTest annotation.

I am just wondering what is the difference between the two?

Which is the best way of writing an integration test in Spring boot?

2 Answers 2

37

The IntegrationTest was deprecated sine spring boot 1.4, so the suggestion is using SpringBootTest after 1.4

Deprecated as of 1.4 in favor of org.springframework.boot.test.context.SpringBootTest with webEnvironment=RANDOM_PORT or webEnvironment=DEFINED_PORT.

Sign up to request clarification or add additional context in comments.

1 Comment

Note : @IntegrationTest is removed in Spring Boot 2.0.0
3

Basic template for writing the integration tests in springboot. the sql group is additional annotation. When ever you want to execute the particular sql queries before and after method run so u can use @SqlGroup annotation.

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MainApplication.class,
            webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SqlGroup({
    @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, 
         scripts = "classpath:beforeTestRun.sql"),
    @Sql(executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, 
         scripts = "classpath:afterTestRun.sql")})

public class CustomerControllerIntTest {}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.