Separate Interactive Test Suites

TJ Miller
TJ Miller
Oct 11, 2017 · 2 min read
Image for post
Image for post
Doesn’t this look nice? — Gabriel Santiago — https://unsplash.com/photos/b-yEdfrvQ50

On a recent Full Stack Radio episode Adam Wathan and Taylor Otwell were talking about testing Laravel applications. During the episode they spoke about isolating interactive integration tests from your normal testing e.g. payment gateways, third-party integrations. One use case would be as contract tests for fakes (really test doubles in general) to mitigate “API drift”.

I’m currently working on an HTTP API that interacts with physical EMV (that chip on your credit card) payment terminals and proxies/transforms the responses. I have integration tests for my API controller responses and didn’t want to have to physically interact with the terminal every time, so I built a TerminalGatewayFake test double with hard-coded responses. Before each deployment we run the Interactive test suite to ensure the fakes and real responses line up.

There are a few ways you can isolate these tests either through manual workflows, filters, test suites, and groups. I decided the best way for me was to create a separate test suites.

To avoid running the interactive test suite with the rest of my tests, manually or via a CI job, I had to explicitly include all the other suites using phpunit --testsuite Api,Feature,Unit. This felt a bit grim and I would rather exclude just that one suite. So I did some digging and found the defaultTestSuite configuration for phpunit. Now, I can easily run my desired test suites by just using phpunit . Then I can manually run phpunit --testsuite Interactive for my interactive contract tests whenever I feel the need to.

Here is an example phpunit.xml config that utilizes defaultTestSuit option.

Want to know more? Check this out!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store