mirror of
https://github.com/logos-storage/asynctest.git
synced 2026-01-04 05:53:10 +00:00
Update Readme with new imports
This commit is contained in:
parent
0fac3d3988
commit
607557d684
46
Readme.md
46
Readme.md
@ -17,16 +17,29 @@ requires "asynctest >= 0.4.3 & < 0.5.0"
|
|||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Simply replace `import unittest` with `import asynctest`, and you can await
|
Replace `import unittest` with one of the following imports, and you can await
|
||||||
asynchronous calls in tests, setup and teardown.
|
asynchronous calls in tests, setup and teardown.
|
||||||
|
|
||||||
|
When you use Nim's standard library only ([asyncdispatch][4] and [unittest][1]):
|
||||||
|
```nim
|
||||||
|
import asynctest/asyncdispatch/unittest
|
||||||
|
```
|
||||||
|
|
||||||
|
When you use [chronos][5] or [unittest2][3], pick the import that matches your
|
||||||
|
choices:
|
||||||
|
|
||||||
|
```nim
|
||||||
|
import asynctest/asyncdispatch/unittest2 # standard async and unittest2
|
||||||
|
import asynctest/chronos/unittest # chronos and standard unittest
|
||||||
|
import asynctest/chronos/unittest2 # chronos and unittest2
|
||||||
|
```
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
||||||
```nim
|
```nim
|
||||||
|
|
||||||
import asynctest
|
import asynctest/asyncdispatch/unittest
|
||||||
import asyncdispatch # alternatively: import chronos
|
|
||||||
|
|
||||||
proc someAsyncProc {.async.} =
|
proc someAsyncProc {.async.} =
|
||||||
# perform some async operations using await
|
# perform some async operations using await
|
||||||
@ -47,17 +60,6 @@ suite "test async proc":
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
setupAll and teardownAll
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
The `setup` and `teardown` code runs before and after every test, just like the
|
|
||||||
standard [unittest][1] module. In addition we provide `setupAll` and
|
|
||||||
`teardownAll`. The `setupAll` code runs once before all tests in the suite, and
|
|
||||||
the `teardownAll` runs once after all tests in the suite. Use these only as a
|
|
||||||
last resort when setting up the test environment is very costly. Be careful that
|
|
||||||
the tests do not modify the environment that you set up, lest you introduce
|
|
||||||
dependencies between tests.
|
|
||||||
|
|
||||||
check eventually
|
check eventually
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
@ -78,12 +80,20 @@ check eventually x == 42
|
|||||||
await future
|
await future
|
||||||
```
|
```
|
||||||
|
|
||||||
Unittest2
|
setupAll and teardownAll
|
||||||
---------
|
------------------------
|
||||||
|
|
||||||
|
The `setup` and `teardown` code runs before and after every test, just like the
|
||||||
|
standard [unittest][1] module. In addition we provide `setupAll` and
|
||||||
|
`teardownAll`. The `setupAll` code runs once before all tests in the suite, and
|
||||||
|
the `teardownAll` runs once after all tests in the suite. Use these only as a
|
||||||
|
last resort when setting up the test environment is very costly. Be careful that
|
||||||
|
the tests do not modify the environment that you set up, lest you introduce
|
||||||
|
dependencies between tests.
|
||||||
|
|
||||||
The [unittest2][3] package is supported. Make sure that you
|
|
||||||
`import asynctest/unittest2` instead of the normal import.
|
|
||||||
|
|
||||||
[1]: https://nim-lang.org/docs/unittest.html
|
[1]: https://nim-lang.org/docs/unittest.html
|
||||||
[2]: https://github.com/nim-lang/nimble
|
[2]: https://github.com/nim-lang/nimble
|
||||||
[3]: https://github.com/status-im/nim-unittest2
|
[3]: https://github.com/status-im/nim-unittest2
|
||||||
|
[4]: https://nim-lang.org/docs/asyncdispatch.html
|
||||||
|
[5]: https://github.com/status-im/nim-chronos/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user