mirror of
https://github.com/status-im/asynctest.git
synced 2025-02-21 09:08:23 +00:00
Add Readme
Update test to match example in Readme.
This commit is contained in:
parent
bb5bc92605
commit
195f8cf668
53
Readme.md
Normal file
53
Readme.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
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
|
||||||
|
requires "asynctest >= 0.1.0 & < 0.2.0"
|
||||||
|
```
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
Simply replace `test` with `asynctest` when you need to await asynchronous calls
|
||||||
|
in the test. The same holds for `asyncsetup` and `asyncteardown`, which allow
|
||||||
|
you to await asynchronous calls during test setup and teardown.
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
```nim
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import asynctest
|
||||||
|
import asyncdispatch # alternatively: import chronos
|
||||||
|
|
||||||
|
proc someAsyncProc {.async.} =
|
||||||
|
# perform some async operations using await
|
||||||
|
|
||||||
|
suite "test async proc":
|
||||||
|
|
||||||
|
asyncsetup:
|
||||||
|
# invoke await in the test setup:
|
||||||
|
await someAsyncProc()
|
||||||
|
|
||||||
|
asyncteardown:
|
||||||
|
# invoke await in the test teardown:
|
||||||
|
await someAsyncProc()
|
||||||
|
|
||||||
|
asynctest "some test":
|
||||||
|
# invoke await in tests:
|
||||||
|
await someAsyncProc()
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
[1]: https://nim-lang.org/docs/unittest.html
|
||||||
|
[2]: https://github.com/nim-lang/nimble
|
@ -2,15 +2,20 @@ import std/unittest
|
|||||||
import std/asyncdispatch
|
import std/asyncdispatch
|
||||||
import pkg/asynctest
|
import pkg/asynctest
|
||||||
|
|
||||||
suite "async tests":
|
proc someAsyncProc {.async.} =
|
||||||
|
# perform some async operations using await
|
||||||
|
discard
|
||||||
|
|
||||||
proc asyncproc {.async.} = discard
|
suite "test async proc":
|
||||||
|
|
||||||
asyncsetup: # allows await in setup
|
asyncsetup:
|
||||||
await asyncproc()
|
# invoke await in the test setup:
|
||||||
|
await someAsyncProc()
|
||||||
|
|
||||||
asyncteardown: # allows await in teardown
|
asyncteardown:
|
||||||
await asyncproc()
|
# invoke await in the test teardown:
|
||||||
|
await someAsyncProc()
|
||||||
|
|
||||||
asynctest "allows await in tests":
|
asynctest "async test":
|
||||||
await asyncproc()
|
# invoke await in tests:
|
||||||
|
await someAsyncProc()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user