|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Domain Driven Design |
| 4 | +nav_order: 2 |
| 5 | +parent: Scenes |
| 6 | +permalink: /scenes/domain-drive-design |
| 7 | +--- |
| 8 | + |
| 9 | +## Test Prompts |
| 10 | + |
| 11 | + Write unit test for following code. |
| 12 | + You MUST return method code only, no explain. |
| 13 | + You MUST return start with @Test annotation. |
| 14 | + You MUST Use English to reply me! |
| 15 | + You are working on a project that uses Spring MVC,Spring WebFlux,JDBC to build RESTful APIs. |
| 16 | + You MUST use should_xx_xx style for test method name. |
| 17 | + You MUST use given-when-then style. |
| 18 | + - Test file should be complete and compilable, without need for further actions. |
| 19 | + - Ensure that each test focuses on a single use case to maintain clarity and readability. |
| 20 | + - Instead of using `@BeforeEach` methods for setup, include all necessary code initialization within each individual test method, do not write parameterized tests. |
| 21 | + | This project uses JUnit 5, you should import `org.junit.jupiter.api.Test` and use `@Test` annotation.- You MUST use MockMvc and test API only. |
| 22 | + - Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc. |
| 23 | + |
| 24 | + |
| 25 | + // here are related classes: |
| 26 | + // class BlogService { |
| 27 | + // blogRepository |
| 28 | + // + public BlogPost createBlog(BlogPost blogDto) |
| 29 | + // + public BlogPost getBlogById(Long id) |
| 30 | + // + public BlogPost updateBlog(Long id, BlogPost blogDto) |
| 31 | + // + public void deleteBlog(Long id) |
| 32 | + // } |
| 33 | + ```java |
| 34 | + @ApiOperation(value = "Create a new blog") |
| 35 | + @PostMapping("/") |
| 36 | + public BlogPost createBlog(@RequestBody CreateBlogRequest request) { |
| 37 | + CreateBlogResponse response = new CreateBlogResponse(); |
| 38 | + BlogPost blogPost = new BlogPost(); |
| 39 | + BeanUtils.copyProperties(request, blogPost); |
| 40 | + BlogPost createdBlog = blogService.createBlog(blogPost); |
| 41 | + BeanUtils.copyProperties(createdBlog, response); |
| 42 | + return createdBlog; |
| 43 | + } |
| 44 | + ``` |
| 45 | + |
| 46 | + Start test code with `@Test` syntax here: |
0 commit comments