liveBook · Manning

Test scenario

As explained in Spring Start Here, Second Edition

A test scenario is a distinct combination of conditions and inputs representing a way an application may behave that should be validated.

A test scenario describes one way an application may behave that should be checked. Identify the scenario, decide how the application should respond, and write a test method to verify it. section 15.1

For a money transfer, scenarios include:

  • The source or destination account cannot be found. section 15.1
  • The source account lacks enough money, an update fails, or all steps succeed. section 15.1

Insufficient funds

If transfers without sufficient funds are forbidden, test that the application throws the expected exception and does not transfer money. If requirements allow a credit limit, account for that limit in the scenario. section 15.1

Figure 15.3 For any piece of logic you test, you need to find the relevant test scenarios. For each test scenario, you write a test method in a test class. You add the test classes in the app’s Maven project test folder. In this figure, the TransferMoneyUnitTests class is a test class that contains the test scenarios for the transferMoney() method. TransferMoneyUnitTests defines multiple test case methods to test each relevant scenario in the transferMoney()’s method logic.

See how scenarios become test methods within a test class for the transfer operation. section 15.1

How Spring Start Here, Second Edition covers it

How deep it goes
Guides readers to identify scenarios, determine desired behavior, and write tests, without detailing test implementation syntax.
Examples
Uses money transfers involving missing accounts, insufficient funds, failed updates, and successful completion.
What it assumes
Assumes knowledge of the application's expected behavior and uses requirements to determine test outcomes.
What you can do after
Evaluate application behavior by matching each relevant scenario to a test method.
How it connects
Connects unit testing with test methods, test classes, and application testability.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.