//inverse.js function inverse(x) { return 1 / x; } // inverse.test.js describe("inverse", () => { it("should return 1 / x", () => { expect(inverse(4)).toBe(0.25); expect(inverse(-8)).toBe(-0.125); }); });
Uber's service topology
src: https://www.uber.com/blog/microservice-architecture/
Concept: Benefit
Test Seeds: stable data
Test Clocks: manageable time
Test Setups: repeatable state setting processes
Test seeds are unchanging data objects in your system.
Any interactions with them give the same answer every time without fail.
GET /users/42 { user_id: 42, balance: 10, ... } GET /users/66 { user_id: 66, balance: 0, ... }
POST /charge/ {amount: 1, used_id: 42} Response 201 {id: 111} POST /charge/ {amount: 1, used_id: 66} Response 400 {"error": "insufficient funds"}
Make time an object in your system.
Stop it for an object, a user, or the entire system.
Move it forward by hours or days.
POST /test-clock/ { name: "1st of the Month", frozenTime: "2023-08-01" } Response 201 {id: 111} POST /gift-card/ { id: 77, ..., expiresAt: "2024-07-31", testClockID: 111} POST /test-clock/111/advance/ { advanceTo: "2024-08-01"} GET /gift-card/77 { id: 77, ..., status: 'expired'}
Make APIs to run various steps to put your system into a desired state.
POST /user/mock-bulk/ { count: 10 } Response 201 [ {id: 110, name: "Joe Small", ...}, {id: 111, name: "Abby Zales", ...}, {id: 112, name: "Troy Barnes", ...}, ... ]
@raiderrobert
mastodon | github
Work at
By Robert Roskam
Engineer and Manager at Unstructured