Test template
Opened this issue · 0 comments
gucio321 commented
Hi there, I'd like to describe used in a project tests template.
each _test.go
file should look as follows:
testdata() map[*TestedType]binaryFormat
method.
this method should specify as much, as possible/necessary test cases in described map formTest_Load(t *testing.T)
this method is really easy
// declare testdata
td := testdata()
// testing loop
for key, value := range td {
// load tested structure using data (value) given
// in some cases, it could be necessary to create bitmuncher (datautils.CreateBitMuncher(value, 0) ) and pass it as an argument to load
s := New()
s.Load(value)
// then just use `assert` to check results
assert.Equal(t, key, s, "unexpected structure loaded")
}
Test_Encode(t *testing.T)
is also really simple
td := testdata()
for key, value := range td {
// encode tested structure into binary form (value)
data := key.Encode()
// use assert to detect differences
assert.Equal(t, value, data, "unexpected data encoded")
}