d2089a6182 | ||
---|---|---|
.github/workflows | ||
asynctest | ||
testmodules | ||
.editorconfig | ||
.gitignore | ||
.tool-versions | ||
License.md | ||
Readme.md | ||
asynctest.nim | ||
asynctest.nimble |
Readme.md
asynctest
Complements the standard unittest module in Nim to allow testing of asynchronous code.
Installation
Use the Nimble package manager to add asynctest to an existing project. Add the following to its .nimble file:
requires "asynctest >= 0.3.0 & < 0.4.0"
Usage
Simply replace import unittest
with import asynctest
, and you can await
asynchronous calls in tests, setup and teardown.
Example
import asynctest
import asyncdispatch # alternatively: import chronos
proc someAsyncProc {.async.} =
# perform some async operations using await
suite "test async proc":
setup:
# invoke await in the test setup:
await someAsyncProc()
teardown:
# invoke await in the test teardown:
await someAsyncProc()
test "async test":
# invoke await in tests:
await someAsyncProc()
Unittest2
The unittest2 package is supported. Make sure that you
import asynctest/unittest2
instead of the normal import.