Fundamentals · Easy · Free
What is a unit test? AAA pattern (Arrange, Act, Assert).
FresherFundamentalsSoftware Engineering & Tools
Unit tests & AAA
For What is a unit test? AAA pattern (Arrange, Act, Assert)., interviewers listen for a crisp definition, how the pieces interact in a real system, and one trade-off or failure mode you have seen or would guard against.
java
@Test
void totalPrice_appliesDiscount() {
// Arrange
Cart cart = new Cart().add(100);
// Act
int total = cart.totalWithDiscount(10);
// Assert
assertEquals(90, total);
}One logical assertion focus per test when possible.