Junior — Middle
What stages does a test case go through in unit testing?
sobes.tech AI
Answer from AI
In unit testing, a test case usually goes through the following stages:
- Arrange — creating and setting up the necessary objects, data, and environment for the test.
- Act — invoking the method or function under test with the prepared parameters.
- Assert — comparing the actual result with the expected one to determine the success of the test.
- Cleanup — releasing resources or resetting the state (often done automatically or not required for simple unit tests).
Example in Java using JUnit:
@Test
public void testSum() {
// Arrange
Calculator calc = new Calculator();
// Act
int result = calc.sum(2, 3);
// Assert
assertEquals(5, result);
}