- Hands-On Full Stack Development with Spring Boot 2.0 and React
- Juha Hinkula
- 147字
- 2021-06-25 21:00:28
Testing in Spring Boot
The Spring Boot test starter package is added to pom.xml by Spring Initializr when we created our project. That is added automatically without any selection in the Spring Initializr page:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
The Spring Boot test starter provides lot of handy libraries for testing, such as JUnit, Mockito, AssertJ, and more. If you look, your project structure already has its own package created for test classes:

By default, Spring Boot uses an in-memory database for testing. We are now using MariaDB, but H2 can also be used for testing by adding the following dependency to the pom.xml file. The scope defines that the H2 database will be used only for running tests; otherwise, the application will use the MariaDB database:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
If you also want to use the default database for testing, you can use the @AutoConfigureTestDatabase annotation.
- 程序員面試筆試寶典(第3版)
- Web Scraping with Python
- C# 從入門到項(xiàng)目實(shí)踐(超值版)
- AIRAndroid應(yīng)用開發(fā)實(shí)戰(zhàn)
- 深入淺出DPDK
- Building Minecraft Server Modifications
- Oracle從入門到精通(第5版)
- 編程數(shù)學(xué)
- 深度學(xué)習(xí):Java語言實(shí)現(xiàn)
- 零基礎(chǔ)Java學(xué)習(xí)筆記
- 持續(xù)集成與持續(xù)交付實(shí)戰(zhàn):用Jenkins、Travis CI和CircleCI構(gòu)建和發(fā)布大規(guī)模高質(zhì)量軟件
- Android Development Tools for Eclipse
- Anaconda數(shù)據(jù)科學(xué)實(shí)戰(zhàn)
- Java從入門到精通(視頻實(shí)戰(zhàn)版)
- C++服務(wù)器開發(fā)精髓