Skip to content

Commit d321afe

Browse files
committed
feat: update java prompts
1 parent ed5e726 commit d321afe

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

java/src/main/kotlin/cc/unitmesh/idea/provider/JavaTestContextProvider.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@ open class JavaTestContextProvider : ChatContextProvider {
2626
val baseTestPrompt = """
2727
|You MUST use should_xx_xx style for test method name.
2828
|You MUST use given-when-then style.
29+
|- Test file should be complete and compilable, without need for further actions.
30+
|- Ensure that each test focuses on a single use case to maintain clarity and readability.
31+
|- Instead of using `@BeforeEach` methods for setup, include all necessary code initialization within each individual test method, do not write parameterized tests.
2932
|""".trimMargin()
3033

3134
items += when {
3235
isController -> {
3336
val testControllerPrompt = baseTestPrompt + """
34-
|You MUST use MockMvc and test API only.
37+
|- You MUST use MockMvc and test API only.
38+
|- Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc.
3539
|""".trimMargin()
3640
ChatContextItem(JavaTestContextProvider::class, testControllerPrompt)
3741
}
3842

3943
isService -> {
4044
val testServicePrompt = baseTestPrompt + """
41-
|You MUST use Mock library and test service only.
45+
|- Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc.
46+
|- Follow the common Spring code style by using the AssertJ library.
47+
|- Assume that the database is empty before each test and create valid entities with consideration for data constraints (jakarta.validation.constraints).
4248
|""".trimMargin()
4349

4450
ChatContextItem(JavaTestContextProvider::class, testServicePrompt)

kotlin/src/main/kotlin/cc/unitmesh/kotlin/provider/KotlinWriteTestService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class KotlinWriteTestService : WriteTestService() {
5151
}
5252

5353
val relatedModels = lookupRelevantClass(project, element)
54-
// should add current class to relatedModels
5554

5655
if (!parentDirPath?.contains("/src/main/kotlin/")!!) {
5756
log.error("Source file is not in the src/main/java directory: ${parentDirPath}")

0 commit comments

Comments
 (0)