main.nim :
func add*(a, b: int): int =
a + b
echo add(3, 5) # 8
test_main.nim :
import std/unittest
import main
suite "my tests":
test "add":
check add(1, 1) == 2
check add(0, 1) == 1
check add(0, 0) == 0
check add(-5, 5) == 0
check add(-5, 10) == 5
Execution and output:
$ nim c test_main.nim
$ ./test_main
8
[Suite] my tests
[OK] add
That is: just compile the test file and run the EXE.
The suite: block is optional. You can simplify it:
import std/unittest
import main
test "add":
check add(1, 1) == 2
check add(0, 1) == 1
check add(0, 0) == 0
check add(-5, 10) == 5
check add(-5, 5) == 0
$ nim c test_main.nim
$ ./test_main
8
[OK] add
You can add as many suite: blocks and test: blocks as you want.