CSE 331�Software Design & Implementation
Spring 2026
Section 2 – Testing and Immutable Reasoning
Administrivia
2
Review - Testing Heuristics
• ≥ 2 Tests
• Statement Coverage
• Branch Coverage
• Loop Coverage
• Exhaustive Testing
Review: JUnit Testing
Review: JUnit Testing
Method Name | Method Description |
assertTrue / assertFalse | Takes in a boolean and asserts that it is true / false |
assertEquals / assertNotEquals | Takes in two objects and asserts that they are equal (using the .equals() method) / not equal |
assertNull / assertNotNull | Takes in an object and asserts that it is null / not null |
assertThrows / assertNotThrows | Given a method, assert that it will throw a certain exception / won’t throw one (Note: this requires a lambda to work) |
For more information, check out the official documentation! https://docs.junit.org/6.0.3/overview.html
Reasoning with Immutable Code
Reasoning With Immutable Code Example
/** Quadruples the value of x
* @requires x > 0
* @return a positive integer y
*/
public static int quadruple(int x) {
int y = 4 * x;
return y;
}
Reasoning With Immutable Code Example
y = 4x
> 4(0)
= 0
/** Quadruples the value of x
* @requires x > 0
* @return a positive integer y
*/
public static int quadruple(int x) {
int y = 4 * x;
return y;
}
Reasoning with Conditionals
Reasoning with If Statements Example
/** Returns the absolute value of a given number x
* @return the integer y such that y = x if x >= 0 or y = -x
* if x < 0
*/
public static int abs(int x) {
if (x < 0) {
int y = -x;
return y; // Return #1
} else {
int y = x;
return y; // Return #2
}
}
Reasoning with If Statements Example
public static int abs(int x) {
if (x < 0) {
int y = -x;
return y; // Return #1
} else {
int y = x;
return y; // Return #2
}
}