Eric Mastro c4b23d73a9 feat: add support for suite before and after
`before` executes async code before all tests in the suite.
`after` executes async code after all tests in the suite.
2022-03-01 07:22:46 +01:00
2021-01-11 13:35:19 +01:00
2021-01-11 13:35:19 +01:00
2021-07-07 10:33:52 +02:00
2021-07-07 10:33:52 +02:00
2021-07-07 10:33:52 +02:00
2022-01-10 11:14:39 +01:00

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":

  setupAll:
    # invoke await in the suite setup:
    await someAsyncProc()

  teardownAll:
    # invoke await in the suite teardown:
    await someAsyncProc()

  setup:
    # invoke await in each test setup:
    await someAsyncProc()

  teardown:
    # invoke await in each 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.

Description
Unit testing of asynchrononous code in Nim
Readme
Languages
Nim 100%