Spring Boot Testing Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Spring Boot Concepts * Spring Framework Testing Concepts =Ov...")
 
Line 6: Line 6:
=Overview=
=Overview=


<font color=darkgray>Process: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4</font>


{{Internal|Spring Framework Testing Concepts|Spring Framework Testing Concepts}}
=Dependencies=
 
<font color=darkgray>Process: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4</font>


Use:
Use:
Line 29: Line 28:
[[@IntegrationTest]], [[@WebIntegrationTest]]
[[@IntegrationTest]], [[@WebIntegrationTest]]


==SpringBoot Test Example==
=SpringBoot Test Example=


<syntaxhighlight lang='java'>
<syntaxhighlight lang='java'>
Line 44: Line 43:
</syntaxhighlight>
</syntaxhighlight>


==Testing Logging Configuration==
=Testing Logging Configuration=


By default, test logging is executed by [[Logback]].
By default, test logging is executed by [[Logback]].

Revision as of 22:21, 14 January 2019

Internal

Overview

Process: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4

Dependencies

Use:

dependencies {
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}

This started dependency pulls everything that is needed to write JUnit tests.

@SpringBootTest - this is required, otherwise beans won't get injected in our tests.

@WebMvcTest

@RunWith(SpringRunner.class)

@IntegrationTest, @WebIntegrationTest

SpringBoot Test Example

@SpringBootTest
@RunWith(SpringRunner.class)
public class MyTests {

    @Autowired
    private SomeComponent someComponentWeWantToTest;

    // ...

}

Testing Logging Configuration

By default, test logging is executed by Logback.

Spring Boot Mockito Support

Spring Boot Mockito Support