2021-01-11 13:23:36 +00:00
|
|
|
asynctest
|
|
|
|
=========
|
|
|
|
|
|
|
|
Complements the standard [unittest][1] module in Nim to allow testing of
|
|
|
|
asynchronous code.
|
|
|
|
|
|
|
|
Installation
|
|
|
|
------------
|
|
|
|
|
|
|
|
Use the [Nimble][2] package manager to add asynctest to an existing project.
|
|
|
|
Add the following to its .nimble file:
|
|
|
|
|
|
|
|
```nim
|
2021-07-07 08:33:36 +00:00
|
|
|
requires "asynctest >= 0.3.0 & < 0.4.0"
|
2021-01-11 13:23:36 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
2021-01-11 16:28:55 +00:00
|
|
|
Simply replace `import unittest` with `import asynctest`, and you can await
|
|
|
|
asynchronous calls in tests, setup and teardown.
|
2021-01-11 13:23:36 +00:00
|
|
|
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
|
|
|
|
```nim
|
|
|
|
|
|
|
|
import asynctest
|
|
|
|
import asyncdispatch # alternatively: import chronos
|
|
|
|
|
|
|
|
proc someAsyncProc {.async.} =
|
|
|
|
# perform some async operations using await
|
|
|
|
|
|
|
|
suite "test async proc":
|
|
|
|
|
2022-02-24 11:15:45 +00:00
|
|
|
setupAll:
|
|
|
|
# invoke await in the suite setup:
|
|
|
|
await someAsyncProc()
|
|
|
|
|
|
|
|
teardownAll:
|
|
|
|
# invoke await in the suite teardown:
|
|
|
|
await someAsyncProc()
|
|
|
|
|
2021-01-11 16:28:55 +00:00
|
|
|
setup:
|
2022-02-24 11:15:45 +00:00
|
|
|
# invoke await in each test setup:
|
2021-01-11 13:23:36 +00:00
|
|
|
await someAsyncProc()
|
|
|
|
|
2021-01-11 16:28:55 +00:00
|
|
|
teardown:
|
2022-02-24 11:15:45 +00:00
|
|
|
# invoke await in each test teardown:
|
2021-01-11 13:23:36 +00:00
|
|
|
await someAsyncProc()
|
|
|
|
|
2021-01-11 16:28:55 +00:00
|
|
|
test "async test":
|
2021-01-11 13:23:36 +00:00
|
|
|
# invoke await in tests:
|
|
|
|
await someAsyncProc()
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2021-07-07 08:32:50 +00:00
|
|
|
Unittest2
|
|
|
|
---------
|
|
|
|
|
|
|
|
The [unittest2][3] package is supported. Make sure that you
|
|
|
|
`import asynctest/unittest2` instead of the normal import.
|
|
|
|
|
2021-01-11 13:23:36 +00:00
|
|
|
[1]: https://nim-lang.org/docs/unittest.html
|
|
|
|
[2]: https://github.com/nim-lang/nimble
|
2021-07-07 08:32:50 +00:00
|
|
|
[3]: https://github.com/status-im/nim-unittest2
|