Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test template #37

Open
gucio321 opened this issue May 21, 2021 · 0 comments
Open

Test template #37

gucio321 opened this issue May 21, 2021 · 0 comments
Labels
documentation Improvements or additions to documentation unittests add/modify unittest (*_test.go) files

Comments

@gucio321
Copy link
Owner

Hi there, I'd like to describe used in a project tests template.
each _test.go file should look as follows:

  1. testdata() map[*TestedType]binaryFormat method.
    this method should specify as much, as possible/necessary test cases in described map form
  2. Test_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")
}
  1. 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")
}
@gucio321 gucio321 added documentation Improvements or additions to documentation unittests add/modify unittest (*_test.go) files labels May 21, 2021
@gucio321 gucio321 pinned this issue May 21, 2021
Repository owner locked and limited conversation to collaborators Aug 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation unittests add/modify unittest (*_test.go) files
Projects
None yet
Development

No branches or pull requests

1 participant