Skip to content

Test template #37

Description

@gucio321

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")
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationunittestsadd/modify unittest (*_test.go) files

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions