mycel-labs / mycel

Apache License 2.0
12 stars 4 forks source link

Improve Test Failure Descriptions #118

Open foxytanuki opened 10 months ago

foxytanuki commented 10 months ago

Context

In our unit tests, we use a structure that includes a slice of structs for defining test cases:

testCases := []struct {
    creator                  string
    name                     string
    parent                   string
    registrationPeriodInYear uint64
    domainOwnership          types.DomainOwnership
    expErr                   error
    fn                       func()
}{

Source

The test functions execute these cases in a specified order:

suite.Run(fmt.Sprintf("Case %d", i), func() {

Source

Issue

The challenge arises when tests fail. The output is not specific about which test types are failing, making it difficult to pinpoint the issue. For example:

--- FAIL: TestKeeperTestSuite/TestRegisterSecondLevelDomain/Case_2 (0.01s)
--- PASS: TestKeeperTestSuite/TestRegisterSecondLevelDomain/Case_3 (0.01s)
--- FAIL: TestKeeperTestSuite/TestRegisterSecondLevelDomain (0.09s)
--- FAIL: TestKeeperTestSuite (0.09s)

Suggested Action

I propose enhancing the test structure by adding descriptive labels or comments to each test case within the struct slice. This adjustment will make the test failure outputs more informative, aiding in quicker identification and resolution of issues.

testCases := []struct {

    creator                  string
    name                     string
    parent                   string
    registrationPeriodInYear uint64
    domainOwnership          types.DomainOwnership
    expErr                   error
    fn                       func()
    desc                     string
}{