API/Unit Tests Flashcards
Servers
- ## local or cloud based
server load handling
- get a bigger server
- get more servers
2a. get a load balancer to distribute
load balancer process distribution methods
- random
- series
- fewest processes
also redistributes load on a server fail
databases
- many servers can communicate with it
- can be partitioned
- can be replicated
database replication strats
- single primary: original has read and write capabilities, sends updates to its replicas
- multi primary: both original and replica has read/write capabilities and update one another
REST API
Representational state transfer application programming interface
REST requests
- URLS identify resources
- HTTP methods to perform operations
- HTTP headers to specify data format for resources that are returned
- HTTP status codes for success/failure (200 OK)
HTTP Methods
- create: POST/PUT
- retrieve: GET
- update: PUT/PATCH
- delete: DELETE
HTTP Headers
2 kinds: content-type and accept
GET examples
GET /users
GET /users/2
GET /users/pages/1 (GET /users?page=1)
GET /users/gender/female (GET /users?gender=female&userid=2) * GET /users/age/18 (GET /users?age=18)
GET /users/2/name
GET /users/2/pets
POST example
POST /users HTTP/1.1
Host: the-website.com
Accept: application/json
Content-Type: application/xml
Content-Length: 49
PUT example
PUT /users/3 HTTP/1.1
Host: the-website.com
Content-Type: application/xml
Content-Length: 52
DELETE example
DELETE /users/2 HTTP/1.1
Host: the-website.com
PATCH example
PATCH /users/1 HTTP/1.1
Host: the-website.com
Content-Type: application/xml
Content-Length: 37
test-driven-development
- software development planning with verification of results as the focus; no coding until we know how it will be tested
- other methods include behavior-driven-development: code until functionality is observed
test case vs suite
- test case: single input with an expected output
- test suite: collection of test cases
unit testing
- each js file is a module
- each function within a module is a unit
- pre and post conditions are important here
integrated testing
test if all modules of your code interact together as intended
system testing
~Dev white box tests~
1. function test; functional reqs are met
2. quality test; non-functional reqs
~Consumer black box tests~
3. acceptance test; customer verifies all reqs
4. installation test; testing in user env (the platform)
good tests
- boundary/edge cases; min/max parameters for input values
- error/empty cases: 0, -1, an empty array, etc.
- test behaviors/functions in combination, not just as units
Node’s assert module
assert.equal(actual, expected)
-value
assert.strictEqual(actual, expected)
-value + data type
- simple set of assertion tests to test invariants
- provides limited feedback on test fails
- 11 methods
Use Mocha for automated testing
at the minimum, use console.log();