diff --git a/example/prompt/autodev/test-prompt.md b/example/prompt/autodev/test-prompt.md index 3fbbf17312..75e134b12a 100644 --- a/example/prompt/autodev/test-prompt.md +++ b/example/prompt/autodev/test-prompt.md @@ -1,26 +1,79 @@ -Write unit test for following code. -You MUST return code only, not explain. -You MUST use given-when-then style. -You MUST use should_xx style for test method name. -When testing controller, you MUST use MockMvc and test API only. +Write unit test for following code. You MUST Use English to reply me! You are working on a project that uses Spring MVC,Spring WebFlux,JDBC to build RESTful APIs. -// class name: BookMeetingRoomRequest -// class fields: meetingRoomId -// class methods: -// super classes: [Object] -// -// class name: BookMeetingRoomResponse -// class fields: bookingId meetingRoomId userId startTime endTime -// class methods: -// super classes: [Object] -// +You MUST use should_xx_xx style for test method name. +You MUST use given-when-then style. +- Test file should be complete and compilable, without need for further actions. +- Ensure that each test focuses on a single use case to maintain clarity and readability. +- Instead of using `@BeforeEach` methods for setup, include all necessary code initialization within each individual test method, do not write parameterized tests. + | 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. +- Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc. + + +// here are related classes: +// 'package: cc.unitmesh.untitled.demo.service.BlogService +// class BlogService { +// blogRepository +// + public BlogPost createBlog(BlogPost blogDto) +// + public BlogPost getBlogById(Long id) +// + public BlogPost updateBlog(Long id, BlogPost blogDto) +// + public void deleteBlog(Long id) +// } +// 'package: cc.unitmesh.untitled.demo.service.BlogService +// class BlogService { +// blogRepository +// + public BlogPost createBlog(BlogPost blogDto) +// + public BlogPost getBlogById(Long id) +// + public BlogPost updateBlog(Long id, BlogPost blogDto) +// + public void deleteBlog(Long id) +// } +// 'package: cc.unitmesh.untitled.demo.entity.BlogPost +// class BlogPost { +// id +// title +// content +// author +// + public BlogPost(String title, String content, String author) +// + public BlogPost() +// + public void setId(Long id) +// + public Long getId() +// + public String getTitle() +// + public void setTitle(String title) +// + public String getContent() +// + public void setContent(String content) +// + public String getAuthor() +// + public void setAuthor(String author) +// } +// 'package: cc.unitmesh.untitled.demo.dto.CreateBlogRequest +// class CreateBlogRequest { +// title +// content +// user +// +// } +Code: ```java -@PostMapping("/{meetingRoomId}/book") - public ResponseEntity bookMeetingRoom(@PathVariable String meetingRoomId, @RequestBody BookMeetingRoomRequest request) { - // 业务逻辑 - BookMeetingRoomResponse response = new BookMeetingRoomResponse(); - // 设置 response 的属性 - return new ResponseEntity<>(response, HttpStatus.CREATED); +@RestController +@RequestMapping("/blog") +public class BlogController { + BlogService blogService; + + public BlogController(BlogService blogService) { + this.blogService = blogService; + } + + @ApiOperation(value = "Get Blog by id") + @GetMapping("/{id}") + public BlogPost getBlog(@PathVariable Long id) { + return blogService.getBlogById(id); + } + + @ApiOperation(value = "Create a new blog") + @PostMapping("/") + public BlogPost createBlog(@RequestBody CreateBlogRequest request) { + BlogPost blogPost = new BlogPost(); + BeanUtils.copyProperties(request, blogPost); + return blogService.createBlog(blogPost); } +} ``` -Start with `import` syntax here: +Start with `import` syntax here: diff --git a/src/main/kotlin/cc/unitmesh/devti/intentions/action/task/TestCodeGenTask.kt b/src/main/kotlin/cc/unitmesh/devti/intentions/action/task/TestCodeGenTask.kt index 414c0dda54..d0e489d4dd 100644 --- a/src/main/kotlin/cc/unitmesh/devti/intentions/action/task/TestCodeGenTask.kt +++ b/src/main/kotlin/cc/unitmesh/devti/intentions/action/task/TestCodeGenTask.kt @@ -85,7 +85,7 @@ class TestCodeGenTask(val request: TestCodeGenRequest) : prompter += runReadAction { testContext.currentClass.format() } } - prompter += "\n```${lang.lowercase()}\nCode:\n${request.selectText}\n```\n" + prompter += "\n```Code:\n${lang.lowercase()}\n${request.selectText}\n```\n" prompter += if (!testContext.isNewFile) { "Start test code with `@Test` syntax here: \n" } else {