@@ -10,23 +10,30 @@ add following two lines at the beginning of your unit tests:
10
10
alice.Node = root1.Invite(alice.Node, root1.Key, alice.PubKey, 1)
11
11
assert.Equal(alice.Len(), 1) // assert anything normally
12
12
13
- # Merge Runtime And Test Assertions
13
+ # Merge Runtime And Unit Test Assertions
14
14
15
15
Especially powerful feature is that even if some assertion violation happens
16
- during the execution of called functions not the test it self. See the above
17
- example. If assertion failure happens inside of the Invite() function instead of
18
- the actual Test function, TestInvite, it's still reported correctly as normal
19
- test failure when TestInvite is executed. It doesn't matter how deep the
20
- recursion is, or if parallel test runs are performed. It works just as you
21
- hoped.
16
+ during the execution of called functions not the test function itself. See the
17
+ above example. If assertion failure happens inside of the Invite() function
18
+ instead of the actual test function, TestInvite, it's still reported correctly
19
+ as normal test failure when TestInvite unit test is executed. It doesn't matter
20
+ how deep the recursion is, or if parallel test runs are performed. It works just
21
+ as you hoped.
22
+
23
+ This is the actual Invite function implementation's first two lines. Even the
24
+ assertion line is written more for runtime detection and active comment, it
25
+ catches all unit test errors as well:
26
+
27
+ func (c Chain) Invite(...) {
28
+ assert.That(c.isLeaf(invitersKey), "only leaf can invite")
22
29
23
30
# Call Stack Traversal During tests
24
31
25
32
The asserter package has super powerful feature. It allows us track assertion
26
33
violations over package and even module boundaries. When using err2 assert
27
- package for runtime Asserts and assert violation happens in what ever package
28
- and module, the whole call stack is brougth to unit test logs. Naturally this is
29
- optinal . Only thing you need to do is set proper asserter and call PushTester.
34
+ package for runtime Asserts and assert violation happens in whatever package
35
+ and module, the whole call stack is brought to unit test logs. Naturally this is
36
+ optional . Only thing you need to do is set proper asserter and call PushTester.
30
37
31
38
// use unit testing asserter
32
39
assert.SetDefault(assert.TestFull)
@@ -66,15 +73,19 @@ And assert package's configuration flags are inserted.
66
73
# Performance
67
74
68
75
assert.That's performance is equal to the if-statement thanks for inlining. And
69
- the most of the generics-based versions are about the equally fast.
76
+ the most of the generics-based versions are about the equally fast. Practice has
77
+ thought that we should prefer other than assert.That because by using detailed
78
+ version like assert.Shorter we get precise error messages automatically. Some
79
+ also prefer readability of specific asserters.
70
80
71
81
If your algorithm is performance-critical please run `make bench` in the err2
72
82
repo and decide case by case. Also you can make an issue or even PR if you would
73
83
like to have something similar like glog.V() function.
74
84
75
- # Technical Notes
85
+ # Naming
76
86
77
- Format string functions need to be own instances because of Go's vet and test
78
- tool integration.
87
+ Because performance has been number one requirement and Go's generics cannot
88
+ discrete slices, maps and channels we have used naming prefixes accordingly: S =
89
+ slice, M = map, C = channel. No prefix is (currently) for the string type.
79
90
*/
80
91
package assert
0 commit comments