2
2
Package assert includes runtime assertion helpers both for normal execution as
3
3
well as a assertion package for Go's testing. What makes solution unique is its
4
4
capable to support both modes with same API. Only thing you need to do is to
5
- add following two lines at the beginning of your unit tests:
5
+ add a PushTester line at the beginning of your unit tests:
6
6
7
7
func TestInvite(t *testing.T) {
8
8
defer assert.PushTester(t)() // push testing variable t beginning of any test
@@ -14,14 +14,14 @@ add following two lines at the beginning of your unit tests:
14
14
# Merge Runtime And Unit Test Assertions
15
15
16
16
Especially powerful feature is that even if some assertion violation happens
17
- during the execution of called functions not the test function itself. See the
18
- above example. If assertion failure happens inside of the Invite() function
19
- instead of the actual test function, TestInvite, it's still reported correctly
20
- as normal test failure when TestInvite unit test is executed . It doesn't matter
21
- how deep the recursion is, or if parallel test runs are performed. It works just
22
- as you hoped.
23
-
24
- This is the actual Invite function implementation's first two lines. Even the
17
+ during the execution of called functions, and not the test function itself, they
18
+ are catched. See the above example. If assertion failure happens inside the
19
+ Invite() function instead of the actual test function, TestInvite, it's still
20
+ reported correctly as normal test failure. It doesn't matter how deep the
21
+ recursion is, or if parallel test runs are performed. It works just as you
22
+ hoped.
23
+
24
+ This is the actual Invite function implementation's first two lines. Even if the
25
25
assertion line is written more for runtime detection and active comment, it
26
26
catches all unit test errors as well:
27
27
0 commit comments