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

Refactor test infrastructure #1444

Merged
merged 1 commit into from
Dec 21, 2018
Merged

Conversation

ob-stripe
Copy link
Contributor

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 a Lazy<> 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-mock

The 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).

: base(stripeMockFixture)
{
}

Copy link
Contributor Author

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()));
Copy link
Contributor Author

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.

@ob-stripe ob-stripe mentioned this pull request Dec 21, 2018
29 tasks
Copy link
Contributor

@remi-stripe remi-stripe left a 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.

@remi-stripe remi-stripe assigned ob-stripe and unassigned remi-stripe Dec 21, 2018
@ob-stripe ob-stripe force-pushed the ob-refactor-test-infra branch from e5175fd to 8b5a863 Compare December 21, 2018 14:41
@ob-stripe ob-stripe merged commit 662911e into integration-v23 Dec 21, 2018
@ob-stripe ob-stripe deleted the ob-refactor-test-infra branch December 21, 2018 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants