-
Notifications
You must be signed in to change notification settings - Fork 572
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
Refactor test infrastructure #1444
Conversation
: base(stripeMockFixture) | ||
{ | ||
} | ||
|
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.
This test (and some others) doesn't rely on GetFixture
, so it doesn't need to receive the StripeMockFixture
instance. My codemod wasn't smart enough to figure that out though, and it's probably best to be consistent anyway.
var exception = Assert.Throws<StripeException>(() => | ||
new CouponService().Create(new CouponCreateOptions())); | ||
var exception = await Assert.ThrowsAsync<StripeException>(async () => | ||
await new CouponService().CreateAsync(new CouponCreateOptions())); |
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.
I changed this test to work around the weirdest Mono issue. With the previous sync version, for some reason this test would work but take exactly 100 seconds to run with Mono. I've really tried to figure out the root cause but came up with nothing. Changing this to async makes the test works instantly with Mono and doesn't change anything for the test's purposes.
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.
This looks good to me. I won't pretend that I fully understand the core of the changes but tests pass and comments did make sense to me.
e5175fd
to
8b5a863
Compare
r? @remi-stripe
cc @stripe/api-libraries
Alright, some context first. When I initialized the new
StripeTests
stripe-mock based suite a few months back, I set up a hack using aLazy<>
object to ensure the initialization (e.g. checking stripe-mock's version) is only done once.This worked, but it's definitely not how this sort of things should be done with xUnit. Also, while this worked for initializing stuff, it doesn't work for cleaning stuff up afterwards. We handled that by simply not cleaning anything up.
This PR reworks the test suite to do things the proper way. All stripe-mock based tests are now grouped in a "collection". Tests in the same collection are run sequentially, and can share collection fixtures.
Two collection fixtures are added:
MockHttpClientFixture
is used to manage the mock HTTP client, for things like asserting requests (and in the future, stubbing requests)StripeMockFixture
is used to manage stripe-mockThe most annoying part of this PR is that test classes that rely on a particular fixture must define a constructor to receive the fixture instance and pass it to the base constructor. I've added helpful error messages to detect when a test class relies on a fixture but didn't define the needed constructor.
The big motivation behind this PR is that I want to port stripe/stripe-ruby#715 to stripe-dotnet, but to do so I need to be able to set up a global teardown function (in order to stop the stripe-mock process if the test suite starts its own).