Skip to content

Commit

Permalink
fix: fix test prompt issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 24, 2023
1 parent c68d93f commit ec89161
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 23 deletions.
97 changes: 75 additions & 22 deletions example/prompt/autodev/test-prompt.md
Original file line number Diff line number Diff line change
@@ -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<BookMeetingRoomResponse> 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:
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ec89161

Please sign in to comment.