LEARN. PRACTICE. EXPLAIN.
Learning paths & interview practiceP
QA foundations
LESSON 1 OF 3 · ABOUT 12 MINUTES + EXERCISE

What is a test case, and what does an assertion prove?

THE IDEA

What it is

A test case describes a situation, an action, and an expected outcome. An assertion compares observation with that expectation. The test is only as useful as the behavior its assertions distinguish; executing code alone does not establish correctness.

Why you need it

A test that merely loads a page can pass while its totals are wrong. A clear expected result gives failures meaning and makes coverage discussions concrete.

How it works

  1. Clarify the behavior and assumptions.
  2. Arrange a controlled starting state.
  3. Perform the action.
  4. Assert the observable result and any important absence of side effects.
JavaScript · Node.js

A small executable assertion example

import assert from "node:assert/strict";
const eligible = subtotal => subtotal >= 1000;
assert.equal(eligible(999), false);
assert.equal(eligible(1000), true);
assert.equal(eligible(1001), true);

Save as discount.mjs and run with Node. These tests demonstrate a specified integer threshold. Real pricing tests must also define currency precision and the exact subtotal calculation.

Good practices and why

  • Derive expected results independently from the implementation being tested.
  • Assert durable outcomes for critical actions, not just visible success messages.

Common mistakes

  • Counting tests as a substitute for identifying risks covered.
  • Copying the implementation into the test as its expected-result calculation.
GUIDED IMPLEMENTATION

Try it yourself

Write a case for changing a profile name, including the value after a reload and what should happen on a rejected save.

What a successful result looks like

The case names preconditions, action, expected persisted state, and the failure behavior.

0 / 6000 characters · Saved on this device. Do not include passwords or private data.

Check your understanding

A save test checks only that a green toast appears. What remains unproven?

Answer the understanding check correctly to record exercise completion.

PUT THE IDEA UNDER PRESSURE

Related interview practice

These scenarios add constraints and follow-up questions to the concepts you just learned.

AlifBay Prep