Comment by skybrian
4 hours ago
The property being tested in this example is “after inserting a row into a database table, the same row can be read back again.”
The insert statement isn’t independent of the database because the table needs to exist and its schema has to allow the inserted values. If the database is generated randomly, you need access to it to generate an insert statement that will work.
This is straightforward to do if the library is designed for it. Using my own TypeScript library [1]:
const insertCaseArb: Arbitrary<InsertCase> = arb.from((pick) => {
const db = pick(dbArb);
const table = pick(arb.of(...db.tables));
const values = pick(rowArbForTable(table));
return {
db,
tableName: table.name,
insert: {
kind: "insert",
table: table.name,
values,
},
};
});
Why might that be difficult? Some property testing libraries don’t let you call a pick function directly.
No comments yet
Contribute on Hacker News ↗