Skip to content

Commit

Permalink
Test different approach of sub-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Feb 26, 2025
1 parent 54be08a commit 8fc626d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 41 deletions.
54 changes: 14 additions & 40 deletions pkg/sdk/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {})
})
})
})
Expand Down
16 changes: 15 additions & 1 deletion pkg/sdk/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8fc626d

Please sign in to comment.