testify icon indicating copy to clipboard operation
testify copied to clipboard

Allow to set a name for Suite

Open d3nnxs opened this issue 2 years ago • 1 comments

Hi,

Maybe I'm wrong with it but it would be very nice to have a possibility to change or decorate the suite name. If I see it correctly suite name is automatically selecting the function name. For example, I have a Test struct which is used several times with different attribute content.

golden.go

type TemplateGoldenTest struct {
	suite.Suite
	Release         string
	Namespace       string
}


func (s *TemplateGoldenTest) TestContainerGoldenTestDefaults() {
	...
}

chart_test.go

for _, template := range listTemplates {
			suite.Run(t, &golden.TemplateGoldenTest{
				Release:        template.name,
				Namespace:      template.namespace,
			})
		}

In test output its hard to differentiate between the different tests.

image

I appreciate any feedback. Thanks.

d3nnxs avatar Jan 16 '23 22:01 d3nnxs

suite.Run is a top-level call for test. So it have the same name as Test-function.

If you want to run several suites inside one test just wrap it with t.Run with suitable names. Like this:

for _, template := range listTemplates {
	t.Run(template.name, func(t *testing.T) {
		suite.Run(t, &golden.TemplateGoldenTest{
			Release:        template.name,
			Namespace:      template.namespace,
		})
	})
}		

kulti avatar Feb 21 '23 13:02 kulti

The workaround suggested above seems good enough.

dolmen avatar Jul 25 '23 02:07 dolmen