Software Testing

120 flashcards by MentisLibrary

The testing pyramid, unit and integration and end-to-end tests, the five test doubles, test-driven development, what coverage does and does not prove, flaky tests, and property-based and snapshot testing.

What is a software test?
Code or a procedure that runs a system with known inputs and asserts that the observed behaviour matches an expected result.
Verification vs validation
Verification asks whether the software was built correctly against its specification. Validation asks whether the right thing was built for the user.
What is the testing pyramid?
A heuristic about proportions: many fast unit tests at the base, fewer integration tests above them, and a small number of slow end-to-end tests at the tip.
What is the ice cream cone anti-pattern?
An inverted pyramid: a suite dominated by manual and end-to-end tests with almost no unit tests underneath.
What is the testing trophy?
An alternative shape, proposed by Kent C. Dodds, that puts static analysis at the base, then unit tests, the most weight on integration tests, and a thin end-to-end layer.
Black box vs white box testing
Black box tests are derived from the specification with no knowledge of the implementation. White box tests use knowledge of the internal structure to reach specific paths.
What is a regression test?
A test kept or added to prove that behaviour which once worked still works, most often written the moment a bug is fixed.
What is a smoke test?
A shallow, fast check that a build's most critical paths work at all, run before it is worth spending time on the full suite.
Functional vs non-functional testing
Functional testing checks what the system does. Non-functional testing checks how well it does it: performance, security, accessibility, reliability, usability.
Error, defect and failure
An error is the human mistake, a defect is the resulting flaw in the code, and a failure is the observable wrong behaviour when that defect is executed.
Why does a defect cost more the later it is found?
Because by then it has been designed around, documented, released, and possibly copied into user data, so fixing it means changing more artefacts than a defect caught while the author still has the code in mind.
What is a test oracle?
The source of truth a test compares actual behaviour against: a hard-coded expected value, a reference implementation, an invariant, or a previously approved output.
What is exploratory testing?
Unscripted human testing in which the tester designs and runs experiments at the same time, using what was just learned to choose the next thing to try.
Arrange, Act, Assert
A three-part structure for a test body: build the world, perform the single action under test, then assert the outcome.
Given, When, Then
The behaviour-driven phrasing of the same three parts, used in Gherkin scenarios so a case reads as a sentence about behaviour rather than about code.
What is equivalence partitioning?
Splitting the input domain into classes the program should treat identically, then testing one representative from each class instead of every value.
What is boundary value analysis?
Testing the values at and immediately either side of each partition edge, because off-by-one and wrong-comparison defects cluster there.
What is a decision table?
A table listing each combination of conditions and the action expected for each, used to derive a complete set of cases for rule-heavy logic.
What is pairwise testing?
Choosing a small set of cases that covers every pair of parameter values at least once, on the observation that most defects involve at most two factors interacting.
What makes a good test name?
It states the condition and the expected behaviour, so the failure line alone tells you what broke without opening the file.
What is negative testing?
Testing that invalid input, wrong ordering and missing permissions are rejected in the way the specification says, rather than silently accepted or crashing.
The one-assertion guideline
Prefer one logical assertion per test so a failure names one behaviour. The rule is about one concept, not literally one assert call.
What is a table-driven test?
One test body run over a list of input and expected-output pairs, keeping the assertion in one place while covering many inputs.
Why should a test avoid branches and loops?
Because control flow in a test can carry the same mistake as the code under test, and a failing test that is itself complicated is hard to debug.
What does test independence require?
That each test passes when run alone, in any order, and in parallel with the others, which means it may not read state another test left behind.
What is a fixture?
The known starting state a test runs against, together with the code that builds it and tears it down.
Object mother vs test data builder
Both create test objects. An object mother exposes named prebuilt examples; a builder exposes a fluent API that starts from a valid default and overrides only the fields the test cares about.
Why should a test state only the data it cares about?
Because irrelevant setup hides which values drive the assertion, and a reader cannot tell whether the customer's country was load-bearing or noise.
What is a unit test?
A test that exercises one piece of behaviour in isolation from the rest of the system, running in memory with no network, database or filesystem.
How fast should a unit test be?
Fast enough that thousands of them finish in seconds, which in practice means a few milliseconds each.