Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suite: allow Suite methods to take *testing.T parameter #1255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

grongor
Copy link

@grongor grongor commented Aug 18, 2022

Summary

Allow suite methods to take *testing.T parameter (as normal tests do). This is BC, and we are already messing with reflection there, so no penalties either.

Changes

Extend allowed suite method signature to include optional *testing.T.
Fail with a friendly error when the signature doesn't match (before it panicked).

Motivation

There are many places where you need t, like for example for mocks and other testing libraries. And typing s.T() get's tedious after a while, and is completely avoidable at no cost :)

type MyTestSuite struct {
	suite.Suite
}

func (s *MyTestSuite) TestLorem(t *testing.T) {
	s.Same(t, s.T())

	mockA := mocks.NewMockA(t)
	mockB := mocks.NewMockB(t)
	mockIHaveTooManyMocks := mocks.NewMockMyLife()

	testStuff(mockA, mockB, mockIHaveTooManyMocks)
}

func (s *MyTestSuite) TestSimple() {
	s.NotEqual("this is", "backwards compatible")
}

@dolmen dolmen changed the title Allow suite methods to take *testing.T parameter suite: allow Suite methods to take *testing.T parameter Oct 16, 2023
@dolmen dolmen added enhancement wontfix pkg-suite Change related to package testify/suite labels Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pkg-suite Change related to package testify/suite wontfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants