Changes for page Tips and Tricks

Last modified by chrisby on 2024/04/01 13:11

From version 1.27
edited by chrisby
on 2023/10/25 20:15
Change comment: There is no comment for this version
To version 1.29
edited by chrisby
on 2024/01/13 18:13
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -6,7 +6,7 @@
6 6  * Don't reinvent the wheel and **use existing test libraries**. There are proven solutions that minimize the effort of creating tests.
7 7  * Use a common **test structure convention** by dividing the test logic into three parts
8 8  *1. **given** (a context → setting up data, fields, and objects)
9 -*1. **when** (something happens → execute production code)
9 +*1. **when** (something happens → define behavior of mocks and execute production code)
10 10  *1. **then** (a certain outcome is expected → check the result via assertions)
11 11  ** Alternative common names for the three steps: **arrange, act, assert**
12 12  * Use additional **simple high-level checks**. For example, when working with a collection, checking the number of items before examining an item from the collection in detail is a good indicator of unexpected or missing items.
... ... @@ -63,3 +63,4 @@
63 63  * **Avoid Cascading Validation**: It would be very cumbersome to perform input validations, such as the famous null checks, and corresponding tests for each unit. A common solution is to define a module consisting of several units. The unit at the top, which receives the input for the first time, validates it once. All subsequent units can safely assume that the input is not null when processing it, and no longer need to explicitly check or write tests for such cases.
64 64  * **Stick to Performance Requirements**: Once a performance test is passed, there is no need to optimize the performance of the code. Any effort in that direction is a waste of resources.
65 65  * **Separate code to be unit tested from third-party code**. All third-party libraries should be hidden behind an interface + wrapper anyway. The unit to be tested should use the interface, which is easy to mock, instead of directly using the third-party library, which is hard to mock.
66 +* **Proportion of test code in the code base**: A comprehensive test suite is critical to keeping the functionality of a software stable when changes are made to the code base. Therefore, it is not uncommon for test code to make up a large portion of the total code base, such as 30-50%.