Skip to content

Commit

Permalink
Update Readme with new imports
Browse files Browse the repository at this point in the history
  • Loading branch information
markspanbroek committed Dec 21, 2023
1 parent 0fac3d3 commit 607557d
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,29 @@ requires "asynctest >= 0.4.3 & < 0.5.0"
Usage
-----

Simply replace `import unittest` with `import asynctest`, and you can await
Replace `import unittest` with one of the following imports, and you can await
asynchronous calls in tests, setup and teardown.

When you use Nim's standard library only ([asyncdispatch][4] and [unittest][1]):
```nim
import asynctest/asyncdispatch/unittest
```

When you use [chronos][5] or [unittest2][3], pick the import that matches your
choices:

```nim
import asynctest/asyncdispatch/unittest2 # standard async and unittest2
import asynctest/chronos/unittest # chronos and standard unittest
import asynctest/chronos/unittest2 # chronos and unittest2
```

Example
-------

```nim
import asynctest
import asyncdispatch # alternatively: import chronos
import asynctest/asyncdispatch/unittest
proc someAsyncProc {.async.} =
# perform some async operations using await
Expand All @@ -47,17 +60,6 @@ suite "test async proc":
```

setupAll and teardownAll
------------------------

The `setup` and `teardown` code runs before and after every test, just like the
standard [unittest][1] module. In addition we provide `setupAll` and
`teardownAll`. The `setupAll` code runs once before all tests in the suite, and
the `teardownAll` runs once after all tests in the suite. Use these only as a
last resort when setting up the test environment is very costly. Be careful that
the tests do not modify the environment that you set up, lest you introduce
dependencies between tests.

check eventually
----------------

Expand All @@ -78,12 +80,20 @@ check eventually x == 42
await future
```

Unittest2
---------
setupAll and teardownAll
------------------------

The `setup` and `teardown` code runs before and after every test, just like the
standard [unittest][1] module. In addition we provide `setupAll` and
`teardownAll`. The `setupAll` code runs once before all tests in the suite, and
the `teardownAll` runs once after all tests in the suite. Use these only as a
last resort when setting up the test environment is very costly. Be careful that
the tests do not modify the environment that you set up, lest you introduce
dependencies between tests.

The [unittest2][3] package is supported. Make sure that you
`import asynctest/unittest2` instead of the normal import.

[1]: https://nim-lang.org/docs/unittest.html
[2]: https://github.com/nim-lang/nimble
[3]: https://github.com/status-im/nim-unittest2
[4]: https://nim-lang.org/docs/asyncdispatch.html
[5]: https://github.com/status-im/nim-chronos/

0 comments on commit 607557d

Please sign in to comment.