liveBook · Manning

Test class

As explained in Spring Start Here, Second Edition

A test class is a class that groups automated test methods for related application behavior.

A test class groups test methods for scenarios involving a particular method’s logic. Each test method checks whether the application behaves as expected in one scenario. section 15.1

For a money transfer method, separate test methods can check what happens when:

  • The source or destination account cannot be found. section 15.1
  • The source account lacks enough money, an update fails, or the transfer succeeds. 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.

The diagram shows a transfer-focused test class containing separate methods for relevant scenarios. section 15.1

How Spring Start Here, Second Edition covers it

How deep it goes
Explains focused classes and scenario-based test methods through a transfer example, without showing test code.
Examples
Uses money-transfer cases involving missing accounts, insufficient funds, failed updates, and successful transfers.
What you can do after
Build it from scratch by organizing scenario-specific test methods around one method’s logic.
How it connects
Connects unit testing with test methods and continuous integration.

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.