assert_
glossary ↓ downloads
track: java · selenium
suite 05 · test frameworks & structure

Fixtures, tags & running subsets

Test frameworks & structure12 min
as a manual tester

You maintain suites: smoke (10 min, every build) vs full regression (2 days, per release).

in automation

@Tag gives tests those labels, and Maven runs exactly the subset you name. Same triage, now executable.

Class-level fixtures: @BeforeAll / @AfterAll

@BeforeEach runs per test; @BeforeAll runs once per class — for expensive shared setup like reading a config file or preparing test data. It must be static (class-level, not instance-level — the OOP lesson's distinction earning its keep):

lifecycle order, all together
@BeforeAll  static void once()      { /* runs 1x, before everything     */ }
@BeforeEach void setUp()           { /* runs before each @Test         */ }
/* ... your @Test methods ...                                          */
@AfterEach  void tearDown()        { /* runs after each @Test          */ }
@AfterAll   static void cleanup()   { /* runs 1x, after everything      */ }
Keep the browser in @BeforeEach. Sharing one browser across tests via @BeforeAll is a tempting speed-up that couples your tests together: test 3 fails because test 2 left the app on the wrong page. Fresh browser per test; buy speed with parallelism (Suite 07) instead.

Tags: smoke vs regression, in code

tagging tests
@Test @Tag("smoke")
void validLogin() { /* ... */ }

@Test @Tag("regression")
void sortByPriceDescending() { /* ... */ }
PowerShell — run subsets
mvn test -Dgroups=smoke              # only @Tag("smoke")
mvn test -DexcludedGroups=slow       # everything except @Tag("slow")
mvn test -Dtest=LoginTest            # one class (from the terminal lesson)
predict: what does this print? think it through, then reveal
output
[INFO] Running LoginTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0   ← only the smoke test ran
[INFO] BUILD SUCCESS

This is how CI stays fast: the pipeline runs -Dgroups=smoke on every commit (minutes) and the full suite nightly (hours). You'll wire exactly that in Suite 07.

Two more annotations worth knowing

⚠ when it breaks — the classics
-Dgroups runs zero tests
[INFO] Tests run: 0 … BUILD SUCCESS

Fix: Tag strings are case-sensitive (@Tag("smoke") vs -Dgroups=Smoke won't match), and in PowerShell wrap the whole flag in quotes: mvn test "-Dgroups=smoke". A green build with 0 tests is a silent lie — always read the count.

I commented out a broken test and forgot it for a month
(no error — that's the problem)

Fix: Commented-out tests vanish from every report. @Disabled("reason") keeps it visible as Skipped: 1 in every run — a todo the whole team can see.

⚡ exercise · triage your suite
  1. Tag your existing tests: the fastest, most critical path gets @Tag("smoke"); everything else @Tag("regression").
  2. Run mvn test -Dgroups=smoke and confirm the count matches your tagging.
  3. @Disable one test with a reason and find the Skipped count in the summary line.
key takeaways
  • @BeforeAll/@AfterAll run once per class (and must be static); keep browsers per-test.
  • @Tag + -Dgroups turns your smoke/regression triage into runnable subsets.
  • @Disabled with a reason beats commented-out tests every time.
← Data-driven tests Reports & failure evidence →