1
1
/*
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
- capable to support both modes with same API. Only thing you need to do is to
4
+ capable to support both modes with the same API. Only thing you need to do is to
5
5
add a PushTester line at the beginning of your unit tests:
6
6
7
7
func TestInvite(t *testing.T) {
@@ -13,13 +13,13 @@ add a PushTester line at the beginning of your unit tests:
13
13
14
14
# Merge Runtime And Unit Test Assertions
15
15
16
- Especially powerful feature is that even if some assertion violation happens
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 .
16
+ If some assertion violation happens in the deep call stack, they are still
17
+ reported as a test failure. See the above example. If assertion failure happens
18
+ somewhere inside the Invite() functions call stack, it's still reported
19
+ correctly as a test failure of the TestInvite. It doesn't matter how deep the
20
+ recursion is, or if parallel test runs are performed. The failure report
21
+ includes all the locations of the meaningful call stack steps. See the chapter
22
+ Call Stack Traveral During Tests .
23
23
24
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
@@ -28,16 +28,12 @@ catches all unit test errors as well:
28
28
func (c Chain) Invite(...) {
29
29
assert.That(c.isLeaf(invitersKey), "only leaf can invite")
30
30
31
- # Call Stack Traversal During tests
31
+ # Call Stack Traversal During Tests
32
32
33
- The asserter package has super powerful feature. It allows us track assertion
34
- violations over package and even module boundaries. When using err2 assert
35
- package for runtime Asserts and assert violation happens in whatever package
36
- and module, the whole call stack is brought to unit test logs. Naturally this is
37
- optional. Only thing you need to do is set proper asserter and call PushTester.
38
-
39
- // use unit testing asserter
40
- assert.SetDefault(assert.TestFull)
33
+ Assert package allows us track assertion violations over package and even module
34
+ boundaries. When an assertion fails during the unit testing, the whole call
35
+ stack is brought to unit test logs. And some help with your IDE, that output can
36
+ be tranferred to a location list, for examplem in Neovim/Vim.
41
37
42
38
With large multi repo environment this has proven to be valuable.
43
39
0 commit comments