Separate Interactive Test Suites

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!