-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fixed suite TearDown ordering #799
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package suite | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is your logic for putting this in a separate file? Does it not make sense to just have this as another test in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other file is huge now, thought could separate the tests based on what we test sortof integration vs small function unit tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I do agree that it's becoming a bit large but I don't think navigating it is still a huge problem. I'd be happy to discuss any ideas you might have about improving its readability & maintainability, whether it involves splitting it up or some other way. |
||
|
||
import ( | ||
"math/rand" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type CallOrderSuite struct { | ||
Suite | ||
callOrder []string | ||
} | ||
|
||
func (s *CallOrderSuite) call(method string) { | ||
time.Sleep(time.Duration(rand.Intn(300)) * time.Millisecond) | ||
s.callOrder = append(s.callOrder, method) | ||
} | ||
|
||
func TestSuiteCallOrder(t *testing.T) { | ||
Run(t, new(CallOrderSuite)) | ||
} | ||
func (s *CallOrderSuite) SetupSuite() { | ||
s.call("SetupSuite") | ||
} | ||
|
||
func (s *CallOrderSuite) TearDownSuite() { | ||
s.call("TearDownSuite") | ||
assert.Equal(s.T(), "SetupSuite;SetupTest;Test A;TearDownTest;SetupTest;Test B;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";")) | ||
} | ||
func (s *CallOrderSuite) SetupTest() { | ||
s.call("SetupTest") | ||
} | ||
|
||
func (s *CallOrderSuite) TearDownTest() { | ||
s.call("TearDownTest") | ||
} | ||
|
||
func (s *CallOrderSuite) Test_A() { | ||
s.call("Test A") | ||
} | ||
|
||
func (s *CallOrderSuite) Test_B() { | ||
s.call("Test B") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not just
defer testSync.Done()
instead of wrapping it in an anonymous function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had some logic which i've removed later. good catch, have updated.