Testing tooling
JUnit test instance lifecycle
Normally creates a test instance per test method. Framework or debugger behavior source-reviewed; actual tool execution NOT RUN.
Formal Syntax & Structure
java syntaxjava
PER_METHOD (default)Working Example
Example Snippetjava
package example.books;
import org.junit.jupiter.api.Test;import org.junit.jupiter.api.BeforeEach;import static org.junit.jupiter.api.Assertions.*;
class ReceiptTest { private int price;
@BeforeEach void setUp() { price = 250; }
@Test void multipliesCountByPrice() { assertEquals(750, Receipt.totalCents(3, price)); }
@Test void rejectsNegativeCount() { assertThrows(IllegalArgumentException.class, () -> Receipt.totalCents(-1, price)); }}