0

I m actually building a REST API that I need to test.

Actually, I have many unit tests to check each method behaviour and now I need to test if I get the expected result when requesting an endpoint, like checking the HTTP response code.

I m working with nodejs and it seems to be a good idea to use supertest module to send HTTP request and to check response codes.

The fact is that if I send request on my real REST API endpoints, I can have many bad data managed in database (when testing PUT / POST / PATCH methods).

But in the other hand, I don't have (in my mind) any way to "mock" or simulate my business job inside of the tests :

(Mocha syntax with ES6)

  describe('get /v1/clients ', function() {
    it('Should get 200 ', function(done) {
      request.get('/v1/clients')
        .query('access_token=' + token + '').expect(200, done);
    });
  });

So you've probably got it :

  • I want to test each API endpoint to be sure that I get what I should get
  • I want to use a standard access_token, not one my database (like a fake one)
  • I want to "simulate" by API, without using real data.

Is that possible ? If yes, How ?

Is this a better choice to check on my real data or not ?

mfrachet
  • 8,772
  • 17
  • 55
  • 110
  • Are you running your tests on your production database ? – L. Meyer Jan 08 '16 at 08:08
  • No, but i think testing shouldnt touch real data – mfrachet Jan 08 '16 at 08:20
  • You're right about that. Like many examples on [mochajs](https://mochajs.org/), you can fill your database with dummy data before each test. – L. Meyer Jan 08 '16 at 08:30
  • @Skahrz Did you ever find a way to do this? I have a way that works when running the tests manually, but for automated testing I get errors that I don't really understand. I have a question on this here: http://stackoverflow.com/questions/41490519/trouble-running-qunit-tests-with-static-server-using-grunt – MdaG Jan 06 '17 at 10:03

0 Answers0