You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spml/src/main/resources/131-java-unit-testing.xml
+63-10Lines changed: 63 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -762,30 +762,83 @@ class MyProcessorTest {
762
762
<rule-subtitle>Use RIGHT-BICEP to guide comprehensive test creation</rule-subtitle>
763
763
</rule-header>
764
764
<rule-description>
765
-
If the code ran correctly, how would I know? How am I going to test this? What else can go wrong? Could this same kind of problem happen anywhere else? What to Test: Use Your RIGHT-BICEP - Are the results **R**ight? Are all the **B**oundary conditions CORRECT? Can you check **I**nverse relationships? Can you **C**ross-check results using other means? Can you force **E**rror conditions to happen? Are **P**erformance characteristics within bounds?
765
+
Key Questions to Guide Test Creation
766
766
</rule-description>
767
+
<rule-notes>
768
+
<notes-title>Description:</notes-title>
769
+
<note-item>
770
+
<note-term>If the code ran correctly, how would I know?</note-term>
771
+
<note-description></note-description>
772
+
</note-item>
773
+
<note-item>
774
+
<note-term>How am I going to test this?</note-term>
775
+
<note-description></note-description>
776
+
</note-item>
777
+
<note-item>
778
+
<note-term>What else can go wrong?</note-term>
779
+
<note-description></note-description>
780
+
</note-item>
781
+
<note-item>
782
+
<note-term>Could this same kind of problem happen anywhere else?</note-term>
783
+
<note-description></note-description>
784
+
</note-item>
785
+
<note-item>
786
+
<note-term>What to Test: Use Your RIGHT-BICEP</note-term>
787
+
<note-description></note-description>
788
+
</note-item>
789
+
<note-item>
790
+
<note-term>Are the results **R**ight?</note-term>
791
+
<note-description></note-description>
792
+
</note-item>
793
+
<note-item>
794
+
<note-term>Are all the **B**oundary conditions CORRECT?</note-term>
795
+
<note-description></note-description>
796
+
</note-item>
797
+
<note-item>
798
+
<note-term>Can you check **I**nverse relationships?</note-term>
799
+
<note-description></note-description>
800
+
</note-item>
801
+
<note-item>
802
+
<note-term>Can you **C**ross-check results using other means?</note-term>
803
+
<note-description></note-description>
804
+
</note-item>
805
+
<note-item>
806
+
<note-term>Can you force **E**rror conditions to happen?</note-term>
807
+
<note-description></note-description>
808
+
</note-item>
809
+
<note-item>
810
+
<note-term>Are **P**erformance characteristics within bounds?</note-term>
811
+
<note-description></note-description>
812
+
</note-item>
813
+
</rule-notes>
767
814
<code-examples>
768
815
<good-example>
769
-
<code-blocklanguage="java"><![CDATA[// Example: Testing a Calculator's add method using RIGHT-BICEP
816
+
<code-blocklanguage="java"><![CDATA[// Testing a calculator's add method, considering RIGHT-BICEP
817
+
public class Calculator {
818
+
public int add(int a, int b) {
819
+
if ((long)a + b > Integer.MAX_VALUE || (long)a + b < Integer.MIN_VALUE) {
820
+
throw new ArithmeticException("Integer overflow");
Copy file name to clipboardExpand all lines: spml/src/test/resources/131-java-unit-testing.mdc
+22-32Lines changed: 22 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -702,19 +702,23 @@ class MyProcessorTest {
702
702
703
703
## Rule 16: Key Questions to Guide Test Creation (RIGHT-BICEP)
704
704
705
-
Title: Key Questions to Guide Test Creation
706
-
Description:
707
-
- If the code ran correctly, how would I know?
708
-
- How am I going to test this?
709
-
- What else can go wrong?
710
-
- Could this same kind of problem happen anywhere else?
711
-
- What to Test: Use Your RIGHT-BICEP
712
-
- Are the results **R**ight?
713
-
- Are all the **B**oundary conditions CORRECT?
714
-
- Can you check **I**nverse relationships?
715
-
- Can you **C**ross-check results using other means?
716
-
- Can you force **E**rror conditions to happen?
717
-
- Are **P**erformance characteristics within bounds?
705
+
Title: Use RIGHT-BICEP to guide comprehensive test creation
706
+
Description: Key Questions to Guide Test Creation
707
+
708
+
**Description:**
709
+
710
+
* **If the code ran correctly, how would I know?**:
711
+
* **How am I going to test this?**:
712
+
* **What else can go wrong?**:
713
+
* **Could this same kind of problem happen anywhere else?**:
714
+
* **What to Test: Use Your RIGHT-BICEP**:
715
+
* **Are the results **R**ight?**:
716
+
* **Are all the **B**oundary conditions CORRECT?**:
717
+
* **Can you check **I**nverse relationships?**:
718
+
* **Can you **C**ross-check results using other means?**:
719
+
* **Can you force **E**rror conditions to happen?**:
720
+
* **Are **P**erformance characteristics within bounds?**:
721
+
718
722
719
723
**Good example:**
720
724
@@ -812,14 +816,8 @@ public class CalculatorTestPoor {
812
816
813
817
## Rule 17: Characteristics of Good Tests (A-TRIP)
814
818
815
-
Title: Characteristics of Good Tests (A-TRIP)
816
-
Description:
817
-
Good tests are A-TRIP:
818
-
- **A**utomatic: Tests should run without human intervention.
819
-
- **T**horough: Test everything that could break; cover edge cases.
820
-
- **R**epeatable: Tests should produce the same results every time, in any environment.
821
-
- **I**ndependent: Tests should not rely on each other or on the order of execution.
822
-
- **P**rofessional: Test code is real code; keep it clean, maintainable, and well-documented.
819
+
Title: Good tests are A-TRIP
820
+
Description: Good tests are A-TRIP: - **A**utomatic: Tests should run without human intervention. - **T**horough: Test everything that could break; cover edge cases. - **R**epeatable: Tests should produce the same results every time, in any environment. - **I**ndependent: Tests should not rely on each other or on the order of execution. - **P**rofessional: Test code is real code; keep it clean, maintainable, and well-documented.
823
821
824
822
**Good example:**
825
823
@@ -940,16 +938,8 @@ public class BadOrderProcessorTest {
940
938
941
939
## Rule 18: Verifying CORRECT Boundary Conditions
942
940
943
-
Title: Verifying CORRECT Boundary Conditions
944
-
Description:
945
-
Ensure your tests check the following boundary conditions (CORRECT):
946
-
- **C**onformance: Does the value conform to an expected format? (e.g., email format, date format)
947
-
- **O**rdering: Is the set of values ordered or unordered as appropriate? (e.g., sorted list, items in a queue)
948
-
- **R**ange: Is the value within reasonable minimum and maximum values? (e.g., age > 0, percentage 0-100)
949
-
- **R**eference: Does the code reference anything external that isn't under direct control of the code itself? (e.g., file existence, network connection - often for integration tests, but can apply to unit tests with mocks)
950
-
- **E**xistence: Does the value exist? (e.g., is non-null, non-zero, present in a set)
951
-
- **C**ardinality: Are there exactly enough values? (e.g., expecting 1 result, 0 results, N results)
952
-
- **T**ime (absolute and relative): Is everything happening in order? At the right time? In time? (e.g., timeouts, sequence of events)
941
+
Title: Ensure your tests check CORRECT boundary conditions
942
+
Description: Ensure your tests check the following boundary conditions (CORRECT): - **C**onformance: Does the value conform to an expected format? (e.g., email format, date format) - **O**rdering: Is the set of values ordered or unordered as appropriate? (e.g., sorted list, items in a queue) - **R**ange: Is the value within reasonable minimum and maximum values? (e.g., age > 0, percentage 0-100) - **R**eference: Does the code reference anything external that isn't under direct control of the code itself? (e.g., file existence, network connection - often for integration tests, but can apply to unit tests with mocks) - **E**xistence: Does the value exist? (e.g., is non-null, non-zero, present in a set) - **C**ardinality: Are there exactly enough values? (e.g., expecting 1 result, 0 results, N results) - **T**ime (absolute and relative): Is everything happening in order? At the right time? In time? (e.g., timeouts, sequence of events)
953
943
954
944
**Good example:**
955
945
@@ -1079,4 +1069,4 @@ public class UserValidationPoorTest {
1079
1069
assertThat(validator.isValidEmailFormat("test@example.com")).isTrue(); // No invalid formats, no nulls.
0 commit comments