Code: Testing in Jennifer
Testing in Jennifer: the code
The shop modules and tests behind the slides. They run with Jennifer 0.27.0 from this folder and need no decks and no network (the HTTP tests start a server on 127.0.0.1:0). Test times in milliseconds differ by machine. Some test files fail on purpose because the slide shows the failure; they are marked below. The failures that cannot be .j files here (lint warnings, a module that forgot a use, the code before a fix) are written out and run by failing.sh.
math_test.j: the first test ("A test is a function whose name starts withtest"). Run:jennifer test math_test.jassertions_test.j: all seven assertions in passing calls ("The assertions, all seven"). Run:jennifer test assertions_test.jcart.j: the cart module:Line,parseQty(1 to 99, else kindcart) andtotal.cart_test.j: its overlay, withtestParseQty(including the regression assertion for 100 on line 11),badQty/testParseQtyRejectsandtestTotal("The overlay", "Errors:assertThrowstakes a name", "Prove the test catches the bug"). Run:jennifer test cart_test.j, and for "Pick, format, measure":jennifer test --filter=Total --coverage cart_test.j(the coverage report also listscart_test.jand a total line, which the slide leaves out).table_test.j: the table-driven black-box test with the deliberately wrong 70 ("Table-driven tests: a loop"). Run:jennifer test table_test.j(fails on purpose).state_test.j: two tests sharing top-level state ("Order and shared state", "setUp, tearDown, --isolated"). Run:jennifer test state_test.j(fails on purpose),jennifer test --isolated state_test.j(passes).fixture_test.j: the same tests withsetUpandtearDown("setUp, tearDown, --isolated"). Run:jennifer test fixture_test.jstock.j: stock levels in a flatdb file (receive) andreserve, which throws aStockError.stock_test.j: its overlay with the throwaway store cleaned up bydefer("A throwaway store, cleaned up bydefer") andtestWrongKind("A wrong kind is a failure too"). Run:jennifer test stock_test.j(fails on purpose intestWrongKind).shop.jandshop_test.j:priceagainst a fake server on a loopback port, and the 404 status checked with try and catch ("A fake server on a loopback port", "A wrong kind is a failure too"). Run:jennifer test shop_test.jfailing.sh: writesfails_test.j(the wrong kind, a function passed instead of its name, a misspelt name) and runs and lints it; runsstock_test.j; the two failing assertions from the notes of "The assertions, all seven";stock.jwithout itsuse convert;("The module still declares its ownuse");cart.jwith the old limit of 100 ("Prove the test catches the bug"; the second failure, intestParseQtyRejects, follows the one the slide shows); and the exit code 2 cases (no test functions, a filter that matches nothing). Run:sh failing.shci.sh: builds a deck-stylesrc/fromcart.j,cart_test.j,stock.jandfails_test.jin a temporary directory and runsjennifer fmt -l,jennifer lintand the test loop ("fmt and lint in CI"), then the tests of a copy ofsrc/alone ("Fixtures travel with the code"). Run:sh ci.sh
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 3.2 KiB | raw |
| assertions_test.j | 903 B | raw |
| cart.j | 911 B | raw |
| cart_test.j | 890 B | raw |
| ci.sh | 1.0 KiB | raw |
| failing.sh | 3.1 KiB | raw |
| fixture_test.j | 477 B | raw |
| math_test.j | 110 B | raw |
| shop.j | 319 B | raw |
| shop_test.j | 1.2 KiB | raw |
| state_test.j | 186 B | raw |
| stock.j | 1.0 KiB | raw |
| stock_test.j | 549 B | raw |
| table_test.j | 409 B | raw |