Beautiful and efficient unit testing for Nim evolved from the standard library unittest module
Go to file
Jacek Sieka f1d70dbb8c
better error message on unexpected exception (#10)
2021-08-17 15:45:12 +02:00
.github/workflows Nim-1.4 fix (#8) 2021-05-22 18:00:55 +02:00
tests fix stand-alone "check" for <Nim-1.4.0 2021-03-22 20:01:37 +01:00
.gitignore initial commit - from https://github.com/nim-lang/Nim/pull/9724 2019-05-19 23:11:17 +02:00
LICENSE.txt initial commit - from https://github.com/nim-lang/Nim/pull/9724 2019-05-19 23:11:17 +02:00
README.md change define prefix and update docs (#7) 2021-04-29 14:20:03 +02:00
config.nims change define prefix and update docs (#7) 2021-04-29 14:20:03 +02:00
nim.cfg initial commit - from https://github.com/nim-lang/Nim/pull/9724 2019-05-19 23:11:17 +02:00
nimdoc.out.css change define prefix and update docs (#7) 2021-04-29 14:20:03 +02:00
unittest2.html change define prefix and update docs (#7) 2021-04-29 14:20:03 +02:00
unittest2.nim better error message on unexpected exception (#10) 2021-08-17 15:45:12 +02:00
unittest2.nimble CI setup 2021-03-19 23:22:19 +01:00

README.md

Introduction

unittest2 is a library for writing unit tests for your Nim programs in the spirit of xUnit.

Features of unittest2 include:

unittest2 started as a pull request to evolve the unittest module in Nim and has since grown into a separate library.

Installing

nimble install unittest2

or add a dependency in your .nimble file:

requires "unittest2"

Usage

See unittest2.html documentation generated by nim buildDocs.

Create a file that contains your unit tests:

import unittest2

suite "Suites can be used to group tests":
  test "A test":
    check: 1 + 1 == 2

Compile and run the unit tests:

nim c -r test.nim

See the tests for more examples!

Porting code from unittest

  • Replace import unittest with import unittest2
  • unittest2 places each test in a separate proc which changes the way templates inside tests are interpreted - some code changes may be necessary

Testing unittest2

# this calls a task in "config.nims"
nim test

License

MIT

Credits