Sobes.tech
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:

  1. Arrange — creating and setting up the necessary objects, data, and environment for the test.
  2. Act — invoking the method or function under test with the prepared parameters.
  3. Assert — comparing the actual result with the expected one to determine the success of the test.
  4. 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);
}
What stages does a test case go through in unit… - sobes.tech