You keep a spreadsheet: one row per test input, columns for username, password, expected result.
Lists and Maps are that spreadsheet in code — and a loop runs your test once per row.
Arrays (from the loops lesson) have a fixed size. Real test data grows and shrinks, so Java's collections are what you'll actually use. Two cover almost everything in test automation:
import java.util.List; import java.util.ArrayList; List<String> invalidEmails = new ArrayList<>(); invalidEmails.add("no-at-sign.com"); invalidEmails.add("@missing-name.com"); invalidEmails.add(""); // boundary: empty! System.out.println(invalidEmails.size()); // 3 System.out.println(invalidEmails.get(0)); // first item (index starts at 0) for (String email : invalidEmails) { System.out.println("Testing rejection of: " + email); }
3 no-at-sign.com Testing rejection of: no-at-sign.com Testing rejection of: @missing-name.com Testing rejection of:
The <String> part declares what the list holds — the compiler then stops you putting anything else in. Note that indexes start at 0: the first element is get(0). Every language you'll meet does this.
import java.util.Map; import java.util.HashMap; Map<String, String> testUser = new HashMap<>(); testUser.put("username", "qa.tester"); testUser.put("password", "S3cure!Pass"); testUser.put("role", "admin"); String role = testUser.get("role"); // "admin"
A Map is one spreadsheet row with named columns. A List<Map<String,String>> — a list of maps — is the whole spreadsheet, and it's precisely the shape data-driven testing frameworks feed your tests in Suite 05.
@DataProvider later, you'll recognize it immediately.Think of a text field you've tested (e.g., a quantity field allowing 1–99).
List<String> of 5 inputs you'd try, including boundaries.Map<String,String> pairing each input with its expected outcome ("accepted" / "rejected").Map<String, String> quantityCases = new HashMap<>(); quantityCases.put("0", "rejected"); // below boundary quantityCases.put("1", "accepted"); // lower boundary quantityCases.put("99", "accepted"); // upper boundary quantityCases.put("100", "rejected"); // above boundary quantityCases.put("-1", "rejected"); // negative
Boundary value analysis, expressed as a data structure — your existing skill in a new syntax.