Skip to content

Commit 16fc139

Browse files
committed
feat: add for test file path
1 parent 4a9ea9c commit 16fc139

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

docs/development/test-prompts.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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:

src/main/kotlin/cc/unitmesh/devti/context/ClassContext.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cc.unitmesh.devti.context
22

33
import cc.unitmesh.devti.context.base.NamedElementContext
4-
import com.google.gson.Gson
54
import com.intellij.psi.PsiElement
65
import com.intellij.psi.PsiReference
6+
import org.jetbrains.kotlin.idea.util.application.runReadAction
77

88
class ClassContext(
99
override val root: PsiElement,
@@ -30,7 +30,10 @@ class ClassContext(
3030
"+ $method"
3131
}
3232

33+
val filePath = runReadAction { root.containingFile.virtualFile.path }
34+
3335
return """
36+
|'filePath: $filePath
3437
|class $className {
3538
| $classFields
3639
| $methodSignatures

0 commit comments

Comments
 (0)