Organize framework unit tests in subtests

This commit is contained in:
drfish
2021-01-30 12:29:26 +08:00
parent 24f13032b3
commit 0c3d8b9720
8 changed files with 194 additions and 146 deletions

View File

@@ -635,8 +635,10 @@ func TestValidateFitArgs(t *testing.T) {
}
for _, test := range argsTest {
if err := validateFitArgs(test.args); err != nil && !strings.Contains(err.Error(), test.expect) {
t.Errorf("case[%v]: error details do not include %v", test.name, err)
}
t.Run(test.name, func(t *testing.T) {
if err := validateFitArgs(test.args); err != nil && !strings.Contains(err.Error(), test.expect) {
t.Errorf("case[%v]: error details do not include %v", test.name, err)
}
})
}
}

View File

@@ -18,6 +18,7 @@ package noderesources
import (
"context"
"fmt"
"reflect"
"testing"
@@ -173,11 +174,13 @@ func TestBrokenLinearFunction(t *testing.T) {
},
}
for _, test := range tests {
function := buildBrokenLinearFunction(test.points)
for _, assertion := range test.assertions {
assert.InDelta(t, assertion.expected, function(assertion.p), 0.1, "points=%v, p=%f", test.points, assertion.p)
}
for i, test := range tests {
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
function := buildBrokenLinearFunction(test.points)
for _, assertion := range test.assertions {
assert.InDelta(t, assertion.expected, function(assertion.p), 0.1, "points=%v, p=%f", test.points, assertion.p)
}
})
}
}