-
Notifications
You must be signed in to change notification settings - Fork 388
Power test suite with external API stub #384
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
Conversation
9ab8d0c to
38b157d
Compare
| public void testPlanList() throws StripeException { | ||
| PlanCollection plans = Plan.all(null); | ||
| assertEquals(1, plans.getData().size()); | ||
| } |
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.
Functional tests change to just a simple test for ever supported API operation on a resource. Response data is generated anyway, so we don't assert strongly against it. Instead we just check that it's the basic format that we expected which tells us that we called the right URL and were able to deserialize the response.
| String data = getFixture("/v1/subscriptions/sub_123", expansions); | ||
| Subscription object = APIResource.GSON.fromJson(data, Subscription.class); | ||
| assertNotNull(object); | ||
| assertNotNull(object.getCustomer()); |
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 is what most model tests will look like: one "basic" test that just tries to deserialize a fixture and one "expansions" test that uses the special * to tell the stub that we want every expandable field expanded. We then try to deserialize the response to make sure that all our ExpandableField instances run. I do a basic assertNotNull on a single expandable field as well just as a basic check that it did something.
| } | ||
|
|
||
| return readUntilEnd(conn.getInputStream()); | ||
| } |
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 still needs cleanup and comments.
Move to using an external API stub in the test suite instead of issuing live API calls so that we can have tests that run more quickly and more reliably. For the time being, I've just converted the plan test suite over to use the new scheme. This is an experimental prototype for demonstrative purposes and should not be merged. See also: * stripe/stripe-go#424 * stripe/stripe-php#357 * stripe/stripe-ruby#553
38b157d to
3edbb15
Compare
|
@brandur Is this PR ready to merge? I'm going to be doing some work on the library over the next two days and would love the newer, faster test suite. Let me know. |
|
@kjc-stripe Good question! So far most of the stripestub-related feedback has been quite positive. It needs a little more work (I'd like to get parameter validation working) before going mainstream, and I should write a slightly more comprehensive installation guide, but it's also not too far off. If you think it'd helpful for your hackathon project, I'm definitely open to bringing this in and iterating in parallel to get everything back into an acceptable place. It's worth nothing though that to get the new speed advantages, it's necessarily to convert test suites over to the new base class and conventions one by one (as is done for plan here). That might be something you're doing anyway for your hackathon project though ... |
|
Closing this one in favor of #452. |
Move to using an external API stub in the test suite instead of issuing live API calls so that we can have tests that run more quickly and more reliably.
For the time being, I've just converted the plan test suite over to use the new scheme.
This is an experimental prototype for demonstrative purposes and should not be merged.
See also: