Loading topic
Calculator, or a file to read. You could write that setup code at the top of every test, but copying the same lines again and again is slow and easy to get wrong. JUnit gives you lifecycle methods so you w5 min readadd work with small numbers? With negative numbers? With zero? You could write a separate test method for each case. That gets long and repetitive fast. JUnit gives you a better tool: the parameterized test.4 min read@TempDir handles them.5 min readCalculator needed nothing else to add two numbers. Real code is rarely that simple. A checkout service might ask a database for prices. An order service might charge a credit card and send an email. You do not want a unit test to touch a real database o5 min read