Manual testing vs automated testing
30 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)ShopLite works, but every change might break it. Before each release you click through the same checks by hand, and an old price can break without anyone noticing. Tests make that check automatic.
Manual testing: checking ShopLite by hand
Manual testing is checking software by using it yourself: you click, send requests and compare what you see with what you expected. A person does every step and judges the result by eye.
Here is a typical release check for ShopLite. Each curl request is one test: a known input and an answer you compare with what you expect, by eye.
# A typical by-hand release check for ShopLite (repeated every release)curl -i http://localhost:8080/api/v1/products/1curl -i http://localhost:8080/api/v1/products/999curl -i -X POST http://localhost:8080/api/v1/auth/login \ -H "Content-Type: application/json" \ -d '{"email": "asha.rao@example.com", "password": "asha-dev-password"}'# ...then read every status code and JSON body by eyeManual checks are useful for a first look at a new screen or endpoint. The trouble starts when you must repeat all of them for every release, carefully, forever.
For ShopLite, one release check means: list the products, place an order, check the total, sign in as a customer, try a wrong password.
Regressions: a change that silently breaks old behaviour
A regression is a bug where something that used to work stops working after a change. The new feature works, so everyone is happy, but an old case broke quietly.
Here a developer adds a 10% bulk discount and checks only the new rule, 10 pens. Watch what happens to the old cases.
Example 1 · A change that silently breaks old orders
import java.math.BigDecimal;import java.math.RoundingMode;
class PriceCalculator { // Version 2: a 10% bulk discount was added for 10 or more pieces static BigDecimal lineTotal(BigDecimal unitPrice, int quantity) { BigDecimal total = unitPrice.multiply(BigDecimal.valueOf(quantity)); if (quantity > 1) { // bug: should be quantity >= 10 total = total.multiply(new BigDecimal("0.90")); } return total.setScale(2, RoundingMode.HALF_UP); }}
public class RegressionDemo { public static void main(String[] args) { BigDecimal pen = new BigDecimal("10.00"); BigDecimal notebook = new BigDecimal("150.00");
System.out.println("10 pens: Rs " + PriceCalculator.lineTotal(pen, 10));
System.out.println("1 pen: Rs " + PriceCalculator.lineTotal(pen, 1)); System.out.println("3 notebooks: Rs " + PriceCalculator.lineTotal(notebook, 3)); }}10 pens: Rs 90.00 1 pen: Rs 10.00 3 notebooks: Rs 405.00
What this code does
- The new rule works: 10 pens at Rs 10 cost Rs 90.00 after 10% off, which is what the developer checked by hand.
- Three notebooks used to cost Rs 450.00 and now cost Rs 405.00, because
quantity > 1gives the discount to every order of 2 or more. Nothing crashed, so nobody noticed: that is a regression.
Regressions are the main reason teams automate tests. When you change a pricing rule, you naturally check the new rule. You rarely re-check the ten old cases that the same method also handles.
Predict the output
Predict the price
The discount was meant for 10 or more pieces. What do these calls return?
Round 1 of 3
What does lineTotal(150, 3) return?
A first automated check in plain Java
An automated test is code that runs your code with a known input, compares the result with the expected value and decides PASS or FAIL by itself. Nobody has to read the numbers.
Now the checks write themselves. One method, check(name, expected, actual), compares with equals and prints PASS or FAIL, so a regression shows up within a second.
Example 2 · Self-checking tests with a hand-rolled check method
import java.math.BigDecimal;import java.math.RoundingMode;
class PriceCalculator { static BigDecimal lineTotal(BigDecimal unitPrice, int quantity) { BigDecimal total = unitPrice.multiply(BigDecimal.valueOf(quantity)); if (quantity >= 10) { total = total.multiply(new BigDecimal("0.90")); } return total.setScale(2, RoundingMode.HALF_UP); }}
public class PriceChecks { static int passed = 0; static int failed = 0;
static void check(String name, Object expected, Object actual) { if (expected.equals(actual)) { passed++; System.out.println("PASS " + name); } else { failed++; System.out.println("FAIL " + name + ": expected " + expected + " but was " + actual); } }
public static void main(String[] args) { BigDecimal pen = new BigDecimal("10.00"); BigDecimal notebook = new BigDecimal("150.00");
check("1 pen", new BigDecimal("10.00"), PriceCalculator.lineTotal(pen, 1)); check("3 notebooks", new BigDecimal("450.00"), PriceCalculator.lineTotal(notebook, 3)); check("9 pens, no discount yet", new BigDecimal("90.00"), PriceCalculator.lineTotal(pen, 9)); check("10 pens, 10% off", new BigDecimal("90.00"), PriceCalculator.lineTotal(pen, 10));
System.out.println(passed + " passed, " + failed + " failed"); }}PASS 1 pen PASS 3 notebooks PASS 9 pens, no discount yet PASS 10 pens, 10% off 4 passed, 0 failed
What this code does
checkcompares withequalsand prints one line per check, so the program itself decides PASS or FAIL. No one has to read and judge the totals.- The four inputs cover the old cases (1 pen, 3 notebooks), the case just below the new limit (9 pens) and the limit itself (10 pens).
Example 3 · The same checks catch the regression
import java.math.BigDecimal;import java.math.RoundingMode;
class PriceCalculator { // Version 2: a 10% bulk discount was added for 10 or more pieces static BigDecimal lineTotal(BigDecimal unitPrice, int quantity) { BigDecimal total = unitPrice.multiply(BigDecimal.valueOf(quantity)); if (quantity > 1) { // bug: should be quantity >= 10 total = total.multiply(new BigDecimal("0.90")); } return total.setScale(2, RoundingMode.HALF_UP); }}
public class PriceChecksAfterChange { static int passed = 0; static int failed = 0;
static void check(String name, Object expected, Object actual) { if (expected.equals(actual)) { passed++; System.out.println("PASS " + name); } else { failed++; System.out.println("FAIL " + name + ": expected " + expected + " but was " + actual); } }
public static void main(String[] args) { BigDecimal pen = new BigDecimal("10.00"); BigDecimal notebook = new BigDecimal("150.00");
check("1 pen", new BigDecimal("10.00"), PriceCalculator.lineTotal(pen, 1)); check("3 notebooks", new BigDecimal("450.00"), PriceCalculator.lineTotal(notebook, 3)); check("9 pens, no discount yet", new BigDecimal("90.00"), PriceCalculator.lineTotal(pen, 9)); check("10 pens, 10% off", new BigDecimal("90.00"), PriceCalculator.lineTotal(pen, 10));
System.out.println(passed + " passed, " + failed + " failed"); }}PASS 1 pen FAIL 3 notebooks: expected 450.00 but was 405.00 FAIL 9 pens, no discount yet: expected 90.00 but was 81.00 PASS 10 pens, 10% off 2 passed, 2 failed
What this code does
- These are the exact checks from Example 2, run against the changed
PriceCalculator. Two FAIL lines appear within a second of the change. - Each FAIL line says which case broke and shows the expected and actual values, so you know where to look before any customer is charged the wrong price.
Three habits make checks useful:
- Pick inputs that cover each rule: no discount, just below the limit, at the limit.
- Write the expected value yourself, from the rule, not by copying what the code prints.
- Run every check after every change, not only the new ones.
Find the bug
Find the weak check
Each pair of lines should be a good automated check. Tap the weak line, then read the fix.
The program printed 405 for three notebooks at Rs 150 each.
Round 1 of 3What a test framework adds
A test framework is a library that finds, runs and reports your tests. In Java the standard one is JUnit 5: you mark each check with @Test and compare results with assertEquals.
Here are the same four checks as a JUnit 5 test class. There is no main method and no hand-made check: each check is a method marked @Test.
Example 4 · The same checks as a JUnit 5 test class
Runs in: a Maven project with JUnit 5 (the test is in src/test/java)
package com.shoplite.pricing;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;
class PriceCalculatorTest {
private static final BigDecimal PEN = new BigDecimal("10.00"); private static final BigDecimal NOTEBOOK = new BigDecimal("150.00");
@Test void onePenCostsItsUnitPrice() { assertEquals(new BigDecimal("10.00"), PriceCalculator.lineTotal(PEN, 1)); }
@Test void threeNotebooksHaveNoDiscount() { assertEquals(new BigDecimal("450.00"), PriceCalculator.lineTotal(NOTEBOOK, 3)); }
@Test void ninePensHaveNoDiscountYet() { assertEquals(new BigDecimal("90.00"), PriceCalculator.lineTotal(PEN, 9)); }
@Test void tenPensGetTenPercentOff() { assertEquals(new BigDecimal("90.00"), PriceCalculator.lineTotal(PEN, 10)); }}$ mvn test ... [INFO] --- surefire:3.5.6:test (default-test) @ shop-pricing --- [INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.shoplite.pricing.PriceCalculatorTest [ERROR] Tests run: 4, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.061 s <<< FAILURE! -- in com.shoplite.pricing.PriceCalculatorTest ... [INFO] Results: [INFO] [ERROR] Failures: [ERROR] PriceCalculatorTest.ninePensHaveNoDiscountYet:26 expected: <90.00> but was: <81.00> [ERROR] PriceCalculatorTest.threeNotebooksHaveNoDiscount:21 expected: <450.00> but was: <405.00> [INFO] [ERROR] Tests run: 4, Failures: 2, Errors: 0, Skipped: 0 [INFO] [INFO] BUILD FAILURE
What this code does
- Each check is now a method marked
@Test, andassertEquals(expected, actual)replaces the hand-rolledcheck. There is nomain: JUnit discovers the four methods by itself. - Run by Maven (
mvn test), the two failures are listed with the test name, the line number and both values, and the build stops with BUILD FAILURE, so the buggy version cannot be packaged.
A framework gives you three things the hand-rolled version lacks:
- Discovery: it finds every test class and
@Testmethod by itself; you never list them in amainmethod. - Reports: it shows which test failed, the expected and actual values and the exact line, and writes report files.
- Failing the build: inside Maven, one failed test stops
mvn package, so broken code cannot be shipped by accident.
Order of execution
What mvn test does
Put the steps in the order Maven and JUnit run them when a test is wrong.
Cost over time: manual checks grow, automated tests stay fast
This loop adds up the minutes a team spends over 12 releases, checking by hand and writing automated tests. Look at where the two totals cross.
Example 5 · Manual versus automated cost over 12 releases
public class TestingCostDemo { public static void main(String[] args) { int newChecksPerRelease = 5; int manualMinutesPerCheck = 2; int minutesToWriteTest = 6;
int manualTotal = 0; int automatedTotal = 0; System.out.println("Release Checks Manual(min) Automated(min)"); for (int release = 1; release <= 12; release++) { int checks = newChecksPerRelease * release; manualTotal += checks * manualMinutesPerCheck; automatedTotal += newChecksPerRelease * minutesToWriteTest; if (release % 3 == 0) { System.out.printf("%7d %6d %11d %14d%n", release, checks, manualTotal, automatedTotal); } } }}Release Checks Manual(min) Automated(min)
3 15 60 90
6 30 210 180
9 45 450 270
12 60 780 360What this code does
- Manual cost adds up all checks in every release, so it grows faster and faster. Automated cost only adds the time to write the new tests; running them takes seconds and is left out.
- Up to release 3 the tests cost more than clicking. By release 6 they are cheaper, and by release 12 the team has saved 420 minutes per cycle of releases. The numbers are a simple model, but the shape is what real teams see.
Manual cost grows with every release, because each release adds new things to check and keeps all the old ones. An automated test costs time once, when you write it, and then runs in milliseconds forever.
At the start, writing tests feels slower than clicking. After a few releases the line crosses, and from then on automated tests are far cheaper and far more reliable.
Next step
Check your understanding
10 quick questions