diff --git a/pkg/sdk/accounts_test.go b/pkg/sdk/accounts_test.go index ac052fd204..d5a7cc3779 100644 --- a/pkg/sdk/accounts_test.go +++ b/pkg/sdk/accounts_test.go @@ -10,53 +10,27 @@ import ( "github.com/stretchr/testify/require" ) -func TestATest(t *testing.T) { - measureTest(t) - // TODO: TestTest not found; add it to the map - - t.Run("level one", func(t *testing.T) { - measureTest(t) - // TODO: TestTest/level_one (TestTest found; add level_one as sub-measurement) +func TestATest(tt *testing.T) { + t := measureTest(tt) - t.Run("level two", func(t *testing.T) { - measureTest(t) - // TODO: TestTest/level_one/level_two (TestTest found; - - t.Run("level three", func(t *testing.T) { - measureTest(t) + t.Run("level one", func(t *T) { + t.Run("level two", func(t *T) { + t.Run("level three", func(t *T) { + assert.Equal(t, 1, 1) }) }) - t.Run("2nd level two", func(t *testing.T) { - measureTest(t) - - t.Run("2nd level three", func(t *testing.T) { - measureTest(t) - }) + t.Run("2nd level two", func(t *T) { + t.Run("2nd level three", func(t *T) {}) }) }) - t.Run("2nd level one", func(t *testing.T) { - measureTest(t) - // TODO: TestTest/level_one (TestTest found; add level_one as sub-measurement) - - t.Run("level two", func(t *testing.T) { - measureTest(t) - // TODO: TestTest/level_one/level_two (TestTest found; - - t.Run("level three", func(t *testing.T) { - measureTest(t) - - t.Run("level four", func(t *testing.T) { - measureTest(t) - - t.Run("level five", func(t *testing.T) { - measureTest(t) - }) - - t.Run("2nd level five", func(t *testing.T) { - measureTest(t) - }) + t.Run("2nd level one", func(t *T) { + t.Run("level two", func(t *T) { + t.Run("level three", func(t *T) { + t.Run("level four", func(t *T) { + t.Run("level five", func(t *T) {}) + t.Run("2nd level five", func(t *T) {}) }) }) }) diff --git a/pkg/sdk/setup_test.go b/pkg/sdk/setup_test.go index 3118c59cbd..7aacd22a55 100644 --- a/pkg/sdk/setup_test.go +++ b/pkg/sdk/setup_test.go @@ -9,9 +9,23 @@ import ( var testMeasurements = measurement.NewTestMeasurements() -func measureTest(t *testing.T) { +type T struct { + *testing.T +} + +// TODO: Proposal for handling sub-testing without the need to call measureTest in them (check accounts_test.go to see how it could look like) +// in this case we could call other function e.g. t := ourTest(tt), because we could use it later for other purposes and inside we would call measureTest anyway +func (t *T) Run(name string, test func(t *T)) { + t.T.Run(name, func(tt *testing.T) { + measureTest(tt) + test(&T{tt}) + }) +} + +func measureTest(t *testing.T) *T { t.Helper() measurement.MeasureTestTime(testMeasurements, t) + return &T{t} } func TestMain(m *testing.M) {