Skip to content

Commit 5bcb537

Browse files
committed
Enhance test case guidelines for ClaudeCode
1 parent 197e364 commit 5bcb537

File tree

1 file changed

+135
-27
lines changed

1 file changed

+135
-27
lines changed
Lines changed: 135 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,155 @@
11
# Test Case Implementation Guidelines
22
Follow the rules below when implementing test code.
33

4-
## Code Inspection Functionality
5-
Implement tests for code inspection functionality using the following steps:
4+
## Common Test Case Implementation
5+
- For individual test data, call `addSqlFile()` from `@src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt` within each test case method separately. This prevents unrelated test data from being registered in other test cases.
6+
- For DAO class test data, use `addDaoJavaFile()` from `@src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt`.
7+
- For Entity test data, use `addEntityJavaFile()` from `@src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt`.
8+
- The default source directory for the virtual test project is `src/java/doma/example`. If you need to register files under a different package name, use `addOtherPackageJavaFile()` or `addOtherPackageSqlFile()`.
9+
- To retrieve information about SQL files registered in the virtual test project, use `findSqlFile()` from `@src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt`.
10+
- To retrieve information about DAO classes registered in the virtual test project, use `findDaoClass()` from `@src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt`.
11+
- If you need to register classes other than DAO or Entity classes, such as subclasses of ExpressionFunction or domain classes, use `addOtherJavaFile()` from `@src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt`.
612

7-
## Implementation of Test Case Classes
13+
## Code Inspection Feature Test Case Implementation
14+
### Description
15+
- Implement tests for code inspection functionality using the following steps.
16+
17+
### Test Case Implementation
818
- Implement test case classes in `@src/test/kotlin/org/domaframework/doma/intellij/inspection`.
919
- Implement test cases for each subclass of **AbstractBaseJavaLocalInspectionTool**.
1020
- Name the test case class as `<InspectionToolName>InspectionTest`.
11-
- The test case class should extend `DomaSqlTest`.
21+
- The test case class should extend `@src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt`.
1222
- Override **setUp()** to add mock **Entity** classes or other necessary components to the virtual project for testing.
1323
- Register the target **AbstractBaseJavaLocalInspectionTool** subclass using **myFixture.enableInspections**.
1424
- In test case functions, retrieve the target Dao class using **DomaSqlTest#findDaoClass()** and test the highlighting results using **myFixture.testHighlighting()**.
25+
- Create the target Dao class or SQL file for inspection.
26+
- Wrap the elements to be error-highlighted with the **<error>** tag and specify the error message to be displayed using the **descr** option.
1527

16-
### Implementation of Test Cases
17-
Create the target Dao class or SQL file for inspection.
18-
Wrap the elements to be error-highlighted with the **<error>** tag and specify the error message to be displayed using the **descr** option.
19-
20-
**Test Data for Dao Classes**
28+
### Test Data
2129
- Implement test data Dao classes in **Java**.
2230
- Annotate test data Dao classes with **@Dao**.
2331
- Place them under the appropriate subpackage in `@src/test/testData/src/main/java/doma/example/dao/inspection`.
2432
- Implement any other necessary classes as needed.
33+
- When creating test cases, prepare and verify the following Entity classes to test parent-child relationships:
34+
- Parent class annotated with @Entity
35+
- Subclass without @Entity annotation
36+
- Subclass annotated with @Entity
37+
- Using the above, create the following test cases for features that use `PsiClass`:
38+
- Test cases using fields/methods defined in parent classes
39+
- Test cases using fields/methods defined in subclasses
40+
- Examples:
41+
- Test that bind variable definition inspection doesn't highlight errors when using fields defined in parent classes
42+
- Test that include/exclude option checking in DAO method annotations doesn't highlight errors when using fields defined in parent classes
43+
- Test that code completion shows fields/methods defined in parent classes as completion candidates
44+
- Create and place SQL files in a directory named after the corresponding Dao class under `@src/test/testData/src/main/resources/META-INF/doma/example/dao`.
45+
- When creating test cases for bind variables, prepare test data that checks instance field methods, static field methods, field methods of elements defined in loop directives, custom functions, and built-in functions. For cases combining multiple variables, ensure comprehensive coverage of all variable combination patterns.
2546

26-
**Entity Test Data**
27-
When creating test cases, prepare and verify the following Entity classes to test parent-child relationships:
28-
- Parent class annotated with @Entity
29-
- Subclass without @Entity annotation
30-
- Subclass annotated with @Entity
47+
## Action Feature Test Case Implementation
48+
### Description
49+
- Action feature test cases should be implemented as subclasses of `DomaSqlTest`.
3150

32-
Using the above, create the following test cases for features that use `PsiClass`:
33-
- Test cases using fields/methods defined in parent classes
34-
- Test cases using fields/methods defined in subclasses
51+
### Test Case Implementation
52+
- Implement test case methods that verify both the visibility of the action in the menu and the state of the system after the action is executed.
3553

36-
**Examples**
37-
- Test that bind variable definition inspection doesn't highlight errors when using fields defined in parent classes
38-
- Test that include/exclude option checking in DAO method annotations doesn't highlight errors when using fields defined in parent classes
39-
- Test that code completion shows fields/methods defined in parent classes as completion candidates
54+
### Test Data
55+
- Prepare the necessary DAO classes and SQL files as test data. Specify the action invocation location by placing a `<caret>` marker in the file where the action will be executed.
4056

41-
#### Test Data for SQL Files
42-
- Create and place SQL files in a directory named after the corresponding Dao class under `@src/test/testData/src/main/resources/META-INF/doma/example/dao`.
43-
- When creating test cases for bind variables, prepare test data that checks instance field methods, static field methods, field methods of elements defined in loop directives, custom functions, and built-in functions.
44-
For cases combining multiple variables, ensure comprehensive coverage of all variable combination patterns.
57+
## Intention Action Feature Test Case Implementation
58+
### Description
59+
- Intention action test cases should be implemented as subclasses of `DomaSqlTest`.
60+
- Implement test case methods that verify both the visibility/non-visibility of the intention action menu and the state after executing the action.
61+
- For menu display tests, check for the existence of a menu item whose family name matches the expected value in the list of actions displayed in the menu.
62+
- After executing the action with `myFixture.launchAction()`, use `myFixture.checkResultByFile()` to compare the file contents after the action with the expected result file.
63+
- For the "Convert SQL file to @Sql annotation" action, test that it can be invoked both from the DAO method and from the SQL file.
64+
65+
### Test Data
66+
- Prepare the necessary DAO classes and SQL files as test data.
67+
- Place a `<caret>` marker at the location where you want to invoke the action.
68+
- As with formatter tests, prepare an expected result file to compare the file contents after the action is executed.
69+
70+
## Line Marker Feature Test Case Implementation
71+
### Description
72+
- Line marker test cases should be implemented as subclasses of `DomaSqlTest`.
73+
74+
### Test Case Implementation
75+
- Implement test case methods that verify the visibility of gutter icons, the number of gutter icons displayed for a file, and the behavior when a gutter icon is clicked.
76+
77+
### Test Data
78+
- Prepare the necessary DAO classes and SQL files as test data.
79+
- For verifying the behavior when a gutter icon is clicked, use the first displayed gutter icon found in the test as the target for the action.
80+
81+
## Code Completion Feature Test Case Implementation
82+
### Description
83+
- Code completion test cases should be implemented as subclasses of `DomaSqlTest`.
84+
85+
### Test Case Implementation
86+
- Implement test case methods that check the contents of the suggestion list (completion suggestions).
87+
- Verify that expected words appear in the suggestions and that unexpected words do not appear.
88+
89+
### Test Data
90+
- Prepare the necessary DAO classes and SQL files as test data.
91+
- Place a `<caret>` marker at the position where code completion should be invoked, and evaluate both the list of expected suggestions and the list of suggestions that should not be shown.
92+
93+
## Reference Resolution Feature Test Case Implementation
94+
### Description
95+
- Reference resolution test cases should be implemented as subclasses of `DomaSqlTest`.
96+
97+
### Test Case Implementation
98+
- Implement test case methods that verify the combination of the source class and the element text for elements inside bind variables.
99+
- For method reference resolution, also check the combination of argument types to ensure that the correct resolution is performed.
100+
101+
### Test Data
102+
- Prepare the necessary DAO classes and SQL files as test data.
103+
- Map the list of target element texts for reference resolution to the information of the source class (and argument types for methods) obtained by resolution, and verify that the actual reference resolution results match the expected mapping.
104+
- Since the same element text may resolve to multiple definitions, the mapping between element text and source class information should be one-to-many.
105+
- For literals or elements that do not have a reference, set the expected value to null.
106+
107+
## Documentation Feature Test Case Implementation
108+
### Description
109+
- Documentation test cases should be implemented as subclasses of `DomaSqlTest`.
110+
111+
### Test Case Implementation
112+
- Implement test case methods that prepare the expected documentation information in HTML format for elements inside bind variables, and compare it with the actual displayed text.
113+
114+
### Test Data
115+
- Prepare the necessary DAO classes and SQL files as test data.
116+
- Place a `<caret>` marker at the position of the element for which you want to reference the documentation information.
117+
- In the expected HTML text, describe the class path using `<a href>` tags. If the element has a type, describe the tags for each nested type. After the tag representing the type information, write the target element text.
118+
119+
## Refactoring Feature Test Case Implementation
120+
### Description
121+
- Refactoring test cases should be implemented as subclasses of `DomaSqlTest`.
122+
- The refactoring feature includes renaming DAO method names and DAO class names. However, since creating test data for class renaming is difficult, only test cases for DAO method renaming are implemented.
123+
- Prepare both the expected data before and after renaming, and implement test case methods that compare the state before and after renaming. Also, verify that the SQL file before renaming does not remain after the operation.
124+
125+
### Test Case Implementation
126+
- Place a `<caret>` marker at the method name you want to rename, and after executing the rename, check that the method name and the associated SQL file name have been renamed accordingly.
127+
128+
### Test Data
129+
- Prepare the necessary DAO classes and SQL files as test data.
130+
131+
## Formatter Feature Test Case Implementation
132+
### Description
133+
- Formatter test cases should be implemented as subclasses of `BasePlatformTestCase`.
134+
- The test compares the test data with the expected value data to verify that the formatting process produces the expected result.
135+
- The execution of the formatting and the comparison with the expected value data are implemented by `formatSqlFile()` in #file:SqlFormatTest.kt.
136+
137+
### Test Case Implementation
138+
- Prepare both a pre-format file and an expected value file for each test case.
139+
- The expected value file should be named `[test data file name]_format.sql` so that the test data and expected value data are displayed together in the project tab.
140+
141+
### Test Data
142+
- Test data files do not need to be registered in the virtual project. Place them under `src/test/testData/sql/formatter`.
143+
144+
## Parser Feature Test Case Implementation
145+
### Description
146+
- Parser test cases should be implemented as subclasses of `ParsingTestCase`.
147+
- Prepare the expected PSI tree structure data, and ensure that the test case method name matches the corresponding file name.
148+
- By calling `doTest()`, the standard parser test provided by the framework will be executed.
149+
150+
### Test Case Implementation
151+
- Obtain the expected PSI tree data by copying the tree information displayed in IntelliJ's debug environment via "Tools > View PSI Structure".
152+
- To capture all differences, including spaces, make sure to check "Show PsiWhiteSpace" before copying the tree information as text.
45153

46-
### Reference
47-
For actual implementation examples using Doma, refer to the [Doma GitHub repository](https://github.com/domaframework/doma/tree/master/integration-test-java/src/main/java/org/seasar/doma/it/dao).
154+
## Reference
155+
- For actual implementation examples using Doma, refer to the [Doma GitHub repository](https://github.com/domaframework/doma/tree/master/integration-test-java/src/main/java/org/seasar/doma/it/dao).

0 commit comments

Comments
 (0)