asynctest/Readme.md
Mark Spanbroek 195f8cf668 Add Readme
Update test to match example in Readme.
2021-01-11 14:23:36 +01:00

1.1 KiB

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.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


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()