5

Does anybody know how to do integration testing of a (React) frontend with Django REST backend. I was able to write functional tests for the frontend with Nightwatch.js and with a fake server API. I am also able to separately test Django REST API - Django offers a LiveServerTestCase that can start a test server for you with a test database and destroy it at the end. I'm wondering if it's possible to somehow use/setup Django's test server that can be called by the front end (i.e. Nightwatch tests). I'm open to other ideas on how I can approach this problem.

foobar
  • 3,849
  • 8
  • 22
  • 32

1 Answers1

4

It is always a bit tricky to integration test heavy client side javascript applications. My tool of choice for this scenario is to use Capybara - a nice Ruby DSL for interacting with web pages - together with a javascript enabled driver. I have used both webkitdriver and poltergeist succesfully. They are both headless so you can run tests in the background without disturbing browsers popping up. (The case with selenium....) There are issues with both in certain cases that I don't remember right now.

Since you are using Django you may want to do testing in Python. I would suggest looking for support for one of the two drivers mentioned above. Also the node.js community may have something useful for this.

froderik
  • 4,642
  • 3
  • 33
  • 43
  • Thank you @froderik, I didn't know about Capybara, will definitely take a look :) My problem was doing an integration testing of frontend that calls a backend REST API, which runs on a different server. So I was going back and forth deciding if I should do integration testing on the frontend side (i.e. use some JS framework) or on the backend side, using Django tools. I was curious to see how other people do this. – foobar Apr 27 '17 at 16:40
  • 1
    I would say most people dont't care to include their JS frontend in integration tests. They believe that it takes too much time to maintain. In my opionion this is the time you have to pay for continuous stability. I would give testing the JS a go and if it turns out to be too unstable or hard for some reason then I would fall back to the backend approach. Another parameter to take into account is the degree of unit test coverage of the different parts. – froderik Apr 28 '17 at 06:39