🧪JUnit
Also known as JUnit 6, JUnit 5, JUnit Jupiter
A common tool for writing tests for Java code. It also runs them.
Think of it like
Think of it like a checklist clipboard for Java code. Each line is a check, and it marks pass or fail.
Example
Emma writes a JUnit test that checks a price of 100 becomes 120 with tax. Gradle runs it with every build.
Definition
Example code
java
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class PriceTest {
@Test
void addsTax() {
assertEquals(120, Price.withTax(100));
}
}Common mistake
Key takeaways
- 1@Test methods. Each test is a marked method.
- 2Assertions. assertEquals and friends check results.
- 3Build tools run it. Maven and Gradle know it.