- 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.
- Embedded Linux Projects Using Yocto Project Cookbook
- Learn TypeScript 3 by Building Web Applications
- Objective-C應用開發全程實錄
- Mastering SVG
- HTML5+CSS3基礎開發教程(第2版)
- 64位匯編語言的編程藝術
- 高級C/C++編譯技術(典藏版)
- Swift語言實戰精講
- MINECRAFT編程:使用Python語言玩轉我的世界
- Web程序設計:ASP.NET(第2版)
- Learning Grunt
- Penetration Testing with the Bash shell
- Robot Framework Test Automation
- Three.js權威指南:在網頁上創建3D圖形和動畫的方法與實踐(原書第4版)
- jMonkeyEngine 3.0 Beginner’s Guide