Testing

TddCalculatorTest

Path
pkg14testing/src/test/java/pkg14testing/TddCalculatorTest.java
Package
pkg14testing
Study order
0
Run
Read this file. It has no standalone main method.
Dependencies
org.junit.jupiter.api.Test

There is no in-browser runner. This is the file from the curriculum, unchanged.

pkg14testing/src/test/java/pkg14testing/TddCalculatorTest.java
1package pkg14testing;2 3import org.junit.jupiter.api.Test;4 5import static org.junit.jupiter.api.Assertions.*;6 7/**8 * TDD example: tests written first, then Calculator (already implemented).9 * Red -> Green -> Refactor cycle.10 */11class TddCalculatorTest {12 13    @Test void addTwoNumbers() { assertEquals(5, new Calculator().add(2, 3)); }14    @Test void divideNormally() { assertEquals(2, new Calculator().divide(6, 3)); }15    @Test void divideByZero() {16        assertThrows(IllegalArgumentException.class, () -> new Calculator().divide(1, 0));17    }18}