-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
## Spring Testing Framework | ||
|
||
[ResultActions](): là một phần của Spring MVC Test framework trong Spring Framework, được sử dụng để kiểm tra và xác nhận kết quả của các yêu cầu HTTP trong quá trình kiểm thử (unit testing hoặc integration testing) của ứng dụng web. | ||
|
||
- [andExpect](): Được sử dụng để xác nhận các điều kiện về kết quả trả về, chẳng hạn như kiểm tra mã trạng thái HTTP, kiểm tra view đã được render, kiểm tra model attribute, v.v. | ||
|
||
- [andDo](): Cho phép bạn thực hiện các hành động bổ sung sau khi yêu cầu đã được xử lý. Thường được sử dụng để ghi log hoặc in ra nội dung trả về để kiểm tra. | ||
|
||
- [andReturn](): Trả về kết quả của yêu cầu HTTP dưới dạng MvcResult, cho phép bạn truy cập đầy đủ thông tin về yêu cầu và trả lời để thực hiện các kiểm tra tùy chỉnh. | ||
|
||
```java | ||
@WebMvcTest(YourController.class) | ||
public class YourControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
public void testYourController() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/your-endpoint")) | ||
.andExpect(MockMvcResultMatchers.status().isOk()) | ||
.andExpect(MockMvcResultMatchers.view().name("your-view")) | ||
.andExpect(MockMvcResultMatchers.model().attributeExists("yourAttribute")) | ||
.andDo(MockMvcResultHandlers.print()); | ||
} | ||
} | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Read Me First | ||
The following was discovered as part of building this project: | ||
|
||
* The original package name 'com.hoangtien2k3.test-springboot-blog-rest-api' is invalid and this project uses 'com.hoangtien2k3.testspringbootblogrestapi' instead. | ||
|
||
# Getting Started | ||
|
||
### Reference Documentation | ||
For further reference, please consider the following sections: | ||
|
||
* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) | ||
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.1.3/maven-plugin/reference/html/) | ||
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.1.3/maven-plugin/reference/html/#build-image) | ||
* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.1.3/reference/htmlsingle/index.html#data.sql.jpa-and-spring-data) | ||
* [Spring Web](https://docs.spring.io/spring-boot/docs/3.1.3/reference/htmlsingle/index.html#web) | ||
* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.1.3/reference/htmlsingle/index.html#using.devtools) | ||
* [Validation](https://docs.spring.io/spring-boot/docs/3.1.3/reference/htmlsingle/index.html#io.validation) | ||
|
||
### Guides | ||
The following guides illustrate how to use some features concretely: | ||
|
||
* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/) | ||
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) | ||
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) | ||
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) | ||
* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) | ||
* [Validation](https://spring.io/guides/gs/validating-form-input/) | ||
|