"How to test void type methods" has always been a topic that many unit testing frameworks are quietly avoiding. Since the existing unit testing methods are mainly to verify the returned results of the tested unit, when the method has no return value, there is no way to test.
From a functional point of view, although the void method does not return any value, its execution will definitely have some potential impact on the outside world. We call it the "side effect" of the method, such as:
1. Initialize external variables (private member variables or global static variables)
2. Assign value to external object
3. Print logs
4. Invoke other external methods
5. ... ...
> A method that does not return any value and does not produce any "side effects" has no meaning to exist.
The essence of these "side effects" can be summarized into two categories: **modify external variables** and **invoke external methods**.
Through the private field accessor and the mock validator of `TestableMock`, the "side effects" can be easily checked.
### 1. Void type method which modify external variables
For example, the following method will modify the private member variable `hashCache` based on the input:
```java
class Demo {
private Map<String,Integer> hashCache = mapOf();
public void updateCache(String domain, String key) {
To test this method, you can use `TestableMock` to quickly mock out the `System.out.println` method. In the mock method body, you can simply call the original method (equivalent to not affecting the original method function, only used for call recording), or leave it blank (equivalent to removing the side effects of the original method).