This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new c9e49db874c Update CLAUDE.md testing standards and guidelines (#37002)
c9e49db874c is described below
commit c9e49db874cb205323ae24c2abfec3d9ce29898f
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Nov 4 12:37:15 2025 +0800
Update CLAUDE.md testing standards and guidelines (#37002)
* Update CLAUDE.md testing standards and guidelines
Refine testing strategy standards, assertJ style preferences, and add
minimum complexity principle for testing decisions. Improve test code examples
and remove redundant preferred example section.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Update calude.md
---------
Co-authored-by: Claude <[email protected]>
---
CLAUDE.md | 43 ++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/CLAUDE.md b/CLAUDE.md
index cd17ba97622..2e6d53fb032 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -50,17 +50,24 @@ Core concepts:
- **Comments**: No code comments - "code as documentation"
### Testing Standards
+
+#### Testing Strategy Standards
- 100% line and branch coverage for all new code
- No redundant test cases - each test validates unique behavior
- Test execution speed: <1 second per test case
- Follow CODE_OF_CONDUCT.md (AIR principle, BCDE design, naming conventions)
- Focus on behavior testing over implementation details
-### Test Code Standards
+#### Test Code Standards
- **Method Naming**: Test methods start with "assert" (not "test")
-- **Assertion Style**: Prefer JUnit 5's `assertTrue()` and `assertFalse()`
over AssertJ's `assertThat(actual, is(expected))`
-- **Code Simplification**: Use direct assertions without unnecessary
intermediate variables
+- **Assertions**: Use AssertJ style: `assertThat(actual, is(expected))`
- **Variables**: Name test results as "actual" (not "result")
+- **Mock Priority Principle**: Prioritize using Mockito mock and mockStatic,
avoid using spy
+- **Minimum Complexity Principle**: Test code must be simpler than business
code, choose the simplest but effective testing method
+
+#### Testing Process Standards
+- **Simplification Strategy**: Minimize test code lines, cognitive load, and
maintenance costs
+- **Single Responsibility Testing**: Each test validates only one core
functionality point
### Intelligent Code Standards
@@ -75,6 +82,7 @@ Core concepts:
- **DRY Principle**: Detect and eliminate duplication automatically
- **Effortless Reading**: Code reads like well-written prose
- **Optimal Abstraction**: Create right level of abstraction for problem domain
+- **Minimum Complexity Principle**: As the highest priority guiding principle
for all testing decisions
#### Evolutionary Code Design
- **Open-Closed Principle**: Code open for extension, closed for modification
@@ -133,42 +141,53 @@ Core concepts:
### Example 1: Intelligent Bug Fix
Before (potential null pointer):
+```java
public void processConnection(DatabaseConnection conn) {
conn.execute(sql);
}
+```
After (context-aware, self-documenting):
+```java
public void processConnection(DatabaseConnection validConnection) {
if (validConnection.isValid()) {
validConnection.execute(sql);
}
}
+```
### Example 2: Pattern-Based New Feature
Following Repository pattern for consistency:
+
+```java
public class MySQLConnectionValidator implements DatabaseValidator {
+
private static final int TIMEOUT_MS = 5000;
-
+
public ValidationResult validate(ConnectionConfig config) {
return timeoutAwareValidation(config);
}
}
+```
### Example 3: Evolutionary Design
Open-closed principle implementation:
+```java
public abstract class AbstractDatabaseConnector {
+
protected abstract Connection createConnection(Config config);
-
+
public final ValidationResult validate(Config config) {
return preValidation(config);
// Implementation in child classes
return createConnection(config);
}
}
+```
### Example 4: Test Code Standards
-Before (avoid - verbose):
+Before:
```java
@Test
void testCalculateTotal() {
@@ -180,7 +199,7 @@ void testCalculateTotal() {
}
```
-After (avoid - intermediate variable):
+After:
```java
@Test
void assertCalculateTotal() {
@@ -191,16 +210,6 @@ void assertCalculateTotal() {
}
```
-Preferred (concise and direct):
-```java
-@Test
-void assertCalculateTotal() {
- List<Order> orders = Arrays.asList(new Order(100), new Order(200));
- OrderService service = new OrderService();
- assertFalse(service.calculateTotal(orders).isEmpty());
-}
-```
-
## Build System
Maven build commands: