Integration Testing
Integration Tests
To view lecture notes for this course, please consult the github-pages.
Distinction between Unit Tests
Introducing dependencies on external modules or data also turns unit tests into integration tests.
If one module misbehaves in a chain of interrelated modules, it is not so immediately clear where to look for the cause of the failure. When code under development relies on a database, a web service, or any other external process or service, enforcing a unit-testable separation is also an opportunity and a driving force to design more modular, more testable and more reusable code.
Distinction between Unit Tests
Starting instructions
Open 2 terminal prompts
run the command
couchdb
cd integration-tests
II. Using text editor of your choice open program.test.js and complete each TODO block.
1. Finish Integration test for the /api/v1/users/badMofos endpoint:
Inspect the payload with the following curl command
Use the telnet command and paste in the following commands to your terminal and hit enter.
Paste this GET request into terminal that is expecting request and line feed and hit enter twice
Use a REST client such as Postman Chrome App or anything else.
Whichever way you use choose you get the following JSON payload
Add assertion to expect function call in line 16 using the payload information.
2. Finish Integration Test for /api/v1/couch/insertDocument endpoint
The Super Test library api docs can be found here SuperTest
Hints to complete the exercise:
1. Use post method in supertest 2. Use set method in supertest and pass in object with Accept and Content-Type headers. 3. Use send method in supertest and pass in object with a name and document property. 4. Make sure to call expect in supertest to do assertion and use previous get request as example. 5. Make sure to end supertest call with end function call or the integration test won't finish. 6. Check statuscode with SuperTest property Status 7. Use assertion methods from Tape Asserts 8. CouchDB api documentation Docs 9. CouchDB driver for node.js (nano) that I am using Docs
Making Rest Call with Curl for Post Request
3. Write an integration test removing the newly created document to /api/v1/couch/deleteDocument/:name
The Super Test library api docs and rest methods can be found here SuperTest
Hints to complete the exercise:
1. Use appropriate supertest method to remove document. 2. Make assertion with the returned status code (204) is usual status for DELETE request.
Making Rest Call with Curl for Delete Request
Last updated