Alexas_Fotos (Public Domain) https://pixabay.com/en/puzzle-drawing-background-696725/

Use Easy-Fix to Run Integration Tests Like Unit Tests

Don’t compromise between mock and live integration tests

  • Write your integration tests such that they run live, allowing network requests, database mutations, etc;
  • Wrap the side-affecting asynchronous tasks with a method from easy-fix.
  • Run those tests, which have a new option:
  • In ‘live’ mode, your tests run just as you wrote them, side effects allowed.
  • In ‘capture’ mode, your tests run like ‘live’ mode, but the arguments and response for each wrapped task are serialized and saved.
  • In ‘replay’ mode, the wrapped tasks are not called. Instead, they respond with the saved (mock) data.

Usage Example

before( function () {
easyFix.wrapAsyncMethod(helpers, 'authenticate');
easyFix.wrapAsyncMethod(isd.IroRequest.prototype, 'getProductOffers');
easyFix.wrapAsyncMethod(isd.TaxRateRequest.prototype, 'getTaxRates');
easyFix.wrapAsyncMethod(restrictions, 'getRestrictonsForUpcs');
easyFix.wrapAsyncMethod(productFees, 'getFeesForUpcs');
});
it('checkout one item', function (done) {
attemptCheckout(
testUser,
checkoutDetails,
function (err, resp, body) {
var bodyJson;
expect(err).to.be.null;
expect(resp.statusCode).to.equal(200);
bodyJson = typeof (body) === 'string' ? JSON.parse(body) : body;
expect(bodyJson.data).to.exist;
expect(bodyJson.error).to.not.exist;
done();
}
);
});
➜  export TEST_MODE=live
➜ mocha test/int/endpoints-with-auth.js -t 20000 -g 'checkout one item'
✓ checkout one item - UPCE (12704ms) 1 passing (16s)➜ export TEST_MODE=capture
➜ mocha test/int/endpoints-with-auth.js -t 20000 -g 'checkout one item'
✓ checkout one item - UPCE (14311ms) 1 passing (17s)➜ export TEST_MODE=replay
➜ mocha test/int/capture.js test/int/endpoints-with-auth.js -g 'checkout one item'
✓ checkout one item - UPCE (71ms) 1 passing (224ms)

Fast but not magical

--

--

We’re powering the next great retail disruption. Learn more about us — https://www.linkedin.com/company/walmartglobaltech/

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