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 88320964e55 Refactor ShardingSphereTable test cases and update 
CLAUDE.md testing principles (#37006)
88320964e55 is described below

commit 88320964e552b37e85cc9ca16817241a82e89f0b
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Nov 4 17:44:14 2025 +0800

    Refactor ShardingSphereTable test cases and update CLAUDE.md testing 
principles (#37006)
    
    - Merge boundary condition tests into main test methods instead of separate 
tests
    - Reorder test methods to match source code method declaration order
    - Remove redundant test cases and maintain concise test coverage
    - Update CLAUDE.md with test case merging strategy and philosophy
    - Add example demonstrating test merging vs excessive splitting
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-authored-by: Claude <[email protected]>
---
 CLAUDE.md                                          | 42 ++++++++++-
 .../schema/model/ShardingSphereTableTest.java      | 85 +++++++++++-----------
 2 files changed, 85 insertions(+), 42 deletions(-)

diff --git a/CLAUDE.md b/CLAUDE.md
index 890f56e6b9d..1c6d2ad1b6a 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -58,18 +58,25 @@ Core concepts:
 - Follow CODE_OF_CONDUCT.md (AIR principle, BCDE design, naming conventions)
 - Focus on behavior testing over implementation details
 - **Branch Minimal Coverage**: Analyze all conditional branches first, 
identify uncovered branches, then write minimal test cases for missing coverage 
only
+- **Test Case Merging Strategy**: Merge boundary condition tests (like null 
checks) into main test methods instead of creating separate test methods
+- **Test Set Minimization**: Avoid excessive test method splitting, maintain 
concise and effective test coverage
 
 #### Test Code Standards
-- **Method Naming**: Test methods start with "assert" (not "test")
+- **Method Naming**: Test methods start with "assert" (not "test"), use 
concise names focused on core functionality
 - **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
+- **Direct Core Logic Testing**: Test methods should directly validate target 
method's core functionality
+- **Boundary Condition Integration**: Include critical boundary condition 
tests (like null checks) within main test methods
 
 #### 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
 - **Test Integration Principle**: New test cases should integrate seamlessly 
with existing test files, maintain consistent naming conventions, and follow 
established code style patterns
+- **Method Order Consistency**: Test method order should match source code 
method declaration order for better maintainability
+- **Redundancy Elimination**: Remove duplicate or unnecessary test cases to 
maintain concise and effective test coverage
+- **Test Case Merging over Splitting**: Prefer merging related tests into 
single comprehensive methods over creating multiple similar test methods
 
 ### Intelligent Code Standards
 
@@ -86,6 +93,7 @@ Core concepts:
 - **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, prioritize simplest implementation approach and 
minimal intermediate variables
+- **Test Merging over Splitting**: Prioritize merging related boundary 
condition tests into main test methods rather than creating separate test 
methods for each edge case
 
 #### Evolutionary Code Design
 - **Open-Closed Principle**: Code open for extension, closed for modification
@@ -250,6 +258,38 @@ void assertCalculateTotal() {
 }
 ```
 
+### Example 6: Test Case Merging Strategy
+
+Before (excessive splitting):
+```java
+@Test
+void assertContainsColumn() {
+    Column column = new Column("id", Types.INTEGER);
+    Table table = new Table("users", Collections.singletonList(column));
+    assertTrue(table.containsColumn("id"));
+    assertFalse(table.containsColumn("name"));
+}
+
+@Test
+void assertContainsColumnWithNull() {
+    Column column = new Column("id", Types.INTEGER);
+    Table table = new Table("users", Collections.singletonList(column));
+    assertFalse(table.containsColumn(null));
+}
+```
+
+After (merged boundary conditions):
+```java
+@Test
+void assertContainsColumn() {
+    Column column = new Column("id", Types.INTEGER);
+    Table table = new Table("users", Collections.singletonList(column));
+    assertTrue(table.containsColumn("id"));
+    assertFalse(table.containsColumn("name"));
+    assertFalse(table.containsColumn(null));
+}
+```
+
 ## Build System
 
 Maven build commands:
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableTest.java
index cbc07095b33..d6802240609 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableTest.java
@@ -34,6 +34,15 @@ import static org.mockito.Mockito.mock;
 
 class ShardingSphereTableTest {
     
+    @Test
+    void assertContainsColumn() {
+        ShardingSphereColumn column = new ShardingSphereColumn("foo_col", 
Types.INTEGER, true, true, false, true, false, false);
+        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.singleton(column), Collections.emptyList(), 
Collections.emptyList());
+        assertTrue(table.containsColumn("foo_col"));
+        assertFalse(table.containsColumn("invalid"));
+        assertFalse(table.containsColumn(null));
+    }
+    
     @Test
     void assertGetColumn() {
         ShardingSphereColumn column = new ShardingSphereColumn("foo_col", 
Types.INTEGER, true, true, false, true, false, false);
@@ -44,17 +53,12 @@ class ShardingSphereTableTest {
     }
     
     @Test
-    void assertFindColumnNamesIfNotExistedFromWithSameColumnSize() {
-        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.singleton(mock()), Collections.emptyList(), 
Collections.emptyList());
-        
assertTrue(table.findColumnNamesIfNotExistedFrom(Collections.singleton("foo_col")).isEmpty());
-    }
-    
-    @Test
-    void assertFindColumnNamesIfNotExistedFromWithDifferentColumnSize() {
+    void assertGetColumnWithDuplicateNames() {
         ShardingSphereColumn column1 = new ShardingSphereColumn("foo_col", 
Types.INTEGER, true, true, false, true, false, false);
-        ShardingSphereColumn column2 = new ShardingSphereColumn("bar_col", 
Types.INTEGER, true, true, false, true, false, false);
+        ShardingSphereColumn column2 = new ShardingSphereColumn("foo_col", 
Types.VARCHAR, false, true, false, true, false, false);
         ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Arrays.asList(column1, column2), Collections.emptyList(), 
Collections.emptyList());
-        
assertThat(table.findColumnNamesIfNotExistedFrom(Collections.singleton("FOO_COL")),
 is(Collections.singletonList("bar_col")));
+        assertThat(table.getAllColumns(), hasSize(1));
+        assertThat(table.getColumn("foo_col"), is(column1));
     }
     
     @Test
@@ -67,69 +71,68 @@ class ShardingSphereTableTest {
     }
     
     @Test
-    void assertContainsColumn() {
-        ShardingSphereColumn column = new ShardingSphereColumn("foo_col", 
Types.INTEGER, true, true, false, true, false, false);
-        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.singleton(column), Collections.emptyList(), 
Collections.emptyList());
-        assertTrue(table.containsColumn("foo_col"));
-        assertFalse(table.containsColumn("invalid"));
+    void assertFindColumnNamesIfNotExistedFromWithSameColumnSize() {
+        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.singleton(mock()), Collections.emptyList(), 
Collections.emptyList());
+        
assertTrue(table.findColumnNamesIfNotExistedFrom(Collections.singleton("foo_col")).isEmpty());
     }
     
     @Test
-    void assertPutIndex() {
+    void assertFindColumnNamesIfNotExistedFromWithDifferentColumnSize() {
+        ShardingSphereColumn column1 = new ShardingSphereColumn("foo_col", 
Types.INTEGER, true, true, false, true, false, false);
+        ShardingSphereColumn column2 = new ShardingSphereColumn("bar_col", 
Types.INTEGER, true, true, false, true, false, false);
+        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Arrays.asList(column1, column2), Collections.emptyList(), 
Collections.emptyList());
+        
assertThat(table.findColumnNamesIfNotExistedFrom(Collections.singleton("FOO_COL")),
 is(Collections.singletonList("bar_col")));
+    }
+    
+    @Test
+    void assertContainsIndex() {
         ShardingSphereIndex index1 = new ShardingSphereIndex("foo_idx_1", 
Collections.emptyList(), false);
         ShardingSphereIndex index2 = new ShardingSphereIndex("foo_idx_2", 
Collections.emptyList(), false);
         ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Arrays.asList(index1, index2), 
Collections.emptyList());
         assertTrue(table.containsIndex("foo_idx_1"));
         assertTrue(table.containsIndex("foo_idx_2"));
         assertFalse(table.containsIndex("invalid"));
-        assertThat(table.getAllIndexes(), hasSize(2));
+        assertFalse(table.containsIndex(null));
     }
     
     @Test
-    void assertGetIndex() {
-        ShardingSphereIndex index = new ShardingSphereIndex("foo_idx", 
Collections.emptyList(), false);
-        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Collections.singleton(index), Collections.emptyList());
-        assertTrue(table.containsIndex("foo_idx"));
-        assertTrue(table.containsIndex("FOO_IDX"));
-        assertFalse(table.containsIndex("invalid"));
-    }
-    
-    @Test
-    void assertRemoveIndex() {
+    void assertGetIndexes() {
         ShardingSphereIndex index1 = new ShardingSphereIndex("foo_idx_1", 
Collections.emptyList(), false);
         ShardingSphereIndex index2 = new ShardingSphereIndex("foo_idx_2", 
Collections.emptyList(), false);
         ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Arrays.asList(index1, index2), 
Collections.emptyList());
-        table.removeIndex("foo_idx_1");
-        assertFalse(table.containsIndex("foo_idx_1"));
-        table.removeIndex("invalid");
-        assertTrue(table.containsIndex("foo_idx_2"));
-        assertThat(table.getAllIndexes(), hasSize(1));
+        assertThat(table.getAllIndexes(), hasSize(2));
+        assertThat(table.getAllIndexes(), hasItems(index1, index2));
     }
     
     @Test
-    void assertGetIndexes() {
+    void assertPutIndex() {
         ShardingSphereIndex index1 = new ShardingSphereIndex("foo_idx_1", 
Collections.emptyList(), false);
         ShardingSphereIndex index2 = new ShardingSphereIndex("foo_idx_2", 
Collections.emptyList(), false);
-        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Arrays.asList(index1, index2), 
Collections.emptyList());
-        assertThat(table.getAllIndexes(), hasItems(index1, index2));
-        assertThat(table.getAllIndexes(), hasSize(2));
+        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+        table.putIndex(index1);
+        table.putIndex(index2);
+        assertTrue(table.containsIndex("foo_idx_1"));
+        assertTrue(table.containsIndex("foo_idx_2"));
+        assertFalse(table.containsIndex("invalid"));
     }
     
     @Test
-    void assertContainsIndex() {
+    void assertRemoveIndex() {
         ShardingSphereIndex index1 = new ShardingSphereIndex("foo_idx_1", 
Collections.emptyList(), false);
         ShardingSphereIndex index2 = new ShardingSphereIndex("foo_idx_2", 
Collections.emptyList(), false);
         ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Arrays.asList(index1, index2), 
Collections.emptyList());
-        assertTrue(table.containsIndex("foo_idx_1"));
+        table.removeIndex("foo_idx_1");
+        assertFalse(table.containsIndex("foo_idx_1"));
+        table.removeIndex("invalid");
+        assertThat(table.getAllIndexes(), hasSize(1));
         assertTrue(table.containsIndex("foo_idx_2"));
-        assertFalse(table.containsIndex("invalid"));
     }
     
     @Test
-    void assertGetConstraints() {
+    void assertGetAllConstraints() {
         ShardingSphereConstraint constraint = new 
ShardingSphereConstraint("foo_tbl_foreign_key", "foo_tbl");
-        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Collections.emptyList(), 
Collections.singletonList(constraint));
-        assertThat(table.getAllConstraints(), hasItems(constraint));
+        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Collections.emptyList(), 
Collections.singleton(constraint));
         assertThat(table.getAllConstraints().size(), is(1));
+        assertThat(table.getAllConstraints(), hasItems(constraint));
     }
 }

Reply via email to