Unit testing of asynchrononous code in Nim
Go to file
Mark Spanbroek 737f01326c Make API identical to std/unittest
Also includes a fix for GcUnsafe2 warnings with chronos.
2021-01-11 17:28:55 +01:00
.github/workflows Asynchronous testing in Nim 2021-01-11 13:35:19 +01:00
tests Make API identical to std/unittest 2021-01-11 17:28:55 +01:00
.editorconfig Asynchronous testing in Nim 2021-01-11 13:35:19 +01:00
.gitignore Asynchronous testing in Nim 2021-01-11 13:35:19 +01:00
.tool-versions Asynchronous testing in Nim 2021-01-11 13:35:19 +01:00
Readme.md Make API identical to std/unittest 2021-01-11 17:28:55 +01:00
asynctest.nim Make API identical to std/unittest 2021-01-11 17:28:55 +01:00
asynctest.nimble Make API identical to std/unittest 2021-01-11 17:28:55 +01:00

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.2.0 & < 0.3.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()