Skip to content

Commit

Permalink
Merge pull request UNICT-DMI#29 from domenicoblanco/improve_readme
Browse files Browse the repository at this point in the history
improvement: add steps to create unit tests
  • Loading branch information
Valeri0p authored May 30, 2022
2 parents 2ea72a9 + 7dcc917 commit d370238
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,22 @@ export QDBotToken="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" # Your bot token
export QDBotIDs="10000000" # Single ID
export QDBotIDs="10000000;10000001;10000002" # Multiple IDs
```

## Write Unit Tests
In order to write Unit Tests, you have to put it inside `tests`.
There are many possibilities,

### Unit Tests without mocking
To add a new unit test without mocking, there are some examples at the beginning of `tests`, but let's inspect how they're implemented:
- `func`: simply the function to mock
- `expected_res`: the expected returned value of the function to test
- `arg`: a tuple that contains the argument(s) of the function to test (the one previously defined in `func`). In case there are no passing arguments, just add an empty tuple object (`tuple()`)
- `is_async`: this is not a compulsory key, should be added and set to `True` only if the function is asynchronous

### Unit Tests with mocking
If is necessary one or more mock(s), it's possible to append three more keys to the unit test.
In case an async function needs to be mocked, its result can be wrapped in an `AsyncMock` and its return value set as a constructor element in the constructor.
The test should have the same keys with three more keys:
- `mock_obj`: it's a list of the objects in which there are the functions to mock. In our examples they often refer to the main object (the one imported from src.main)
- `mock_func`: an array of strings, it indicates the functions to mock
- `mock_ret`: a list of the returned values

0 comments on commit d370238

Please sign in to comment.