Skip to content

TestCase

class TestCase

A test case in a test framework serves as the smallest, atomic unit for testing a specific functionality or aspect of an application. It contains one or more test actions that define specific conditions, actions and expected results. The TestCase is used to ensure that individual parts of the application function as intended. It isolates the code to be tested from other parts of the application in order to achieve accurate and consistent results. By executing TestCases, developers can recognise and correct errors at an early stage, which contributes to the stability and quality of the software.

  • Add a test case from the resource selection:

Best Practice

In general, it makes sense to store the corresponding test cases aside the object (controller) to be tested.

Best Practice

  • Your unit test name should express a specific requirement.
  • This requirement should be derived from either a business requirement or a technical requirement.
  • The requirement shall be broken down into small enough pieces, each of which represents a test case.

To be able to deduce the test behavior of a test case based on its name, it makes sense to use the following elements in the name: test_[Type or name of unit to be tested]_[Functionality being tested]_[Expected result]

  • Write a comment to explain the test case!

Best Practice

Unit tests are just as much about documentation as they are about testing functionality. You should always assume that someone else is going to read your tests in a year, and that they should not have a hard time understanding your intent.

Further properties

Structure of a test case

  1. Definition for which controller a test case was formulated. It is also possible to formulate a TestCase for an interface. In this case, the same TestCase can be used for all controllers that implement this interface.
  2. There are three subdivisions within the test case (setup, test, teardown). These groups are purely organisational. It is advisable to structure a test case in such a way that the setup section is used to bring the controller into a certain state in order to then carry out the actual test in the test section. The teardown section is used to restore the initial situation.
  3. Set actions can be used to write values to a variable or execute methods. Typically, set actions consist of a source element (value to be written) and a target element (target of the write operation).
  4. Test actions can be used to check variables for a certain value. Values can be tested for equality, inequality or greater.