fast-check
https://gyazo.com/0f88c371e2bf6e22f360b30ffc3e8c81
Property based testingでTypeScriptのTestをするlibrary
docs
github
API Reference
fc.property
fast-checkのArbitray
fast-checkのRunner
例
code:ts
fc.assert(
fc.property(fc.string(), fc.string(), fc.string(), (a, b, c) => {
return contains(a + b + c, b);
}),
);
3つのstring値を生成してる
Track Record | fast-check
fast-checkによってOSSのバグが見つかった実例
#WIP
Vitestとの連携
特別な設定は不要そう
普通に、test(..)の中でfc.assertを呼べば良い
https://fast-check.dev/docs/configuration/global-settings/#vitest
global settings
生成するケース数とか
https://www.npmjs.com/package/@fast-check/vitest
1つ懸念点はIn-source testingに抵抗があるなmrsekut.icon
fc.Command
Command pattern的なシステムとかreducerを使う系のもののテストという感じmrsekut.icon
テスト用にもCommandとその事前条件を定義しておき、事前条件を満たすものだけを、ランダムに投げていくテスト
Model-based Testing
Statefull Property Testing
https://qiita.com/kiwa-y/items/354744ef7393d07a8928?utm_source=pocket_saves#ケーススタディ-書籍の貸出システム
code:ts
class AddBookNewCommand implements fc.Command<Model, BookRepository> {
constructor(readonly value: Book) {}
check = (m: Readonly<Model>) => {
return !hasIsbn(m, this.value.isbn);
};
async run(m: Model, r: BookRepository): Promise<void> {
await r.addBook(
this.value.isbn,
this.value.title,
this.value.author,
this.value.owned,
this.value.available
);
m.set(this.value.isbn, this.value);
}
toString = () => AddBookNew (${this.value.isbn});
}
classで作るんだ
https://fast-check.dev/docs/introduction/
introduction
core-blocks
fast-checkのArbitray
properties.md
fast-checkのRunner
advanced
fake-data.md
fuzzing.md
model-based-testing.md
Model-based Testing
race-conditions.md
configuration
custom-reports.md
global-settings.md
index.md
larger-entries-by-default.md
timeouts.md
user-definable-values.md
ecosystem.md
tutorials
quick-start
detect-race-conditions
index.md
multiple-batches-of-calls.mdx
one-step-closer-to-real-usages.mdx
snippets.mjs
snippets.spec.mjs
the-missing-part.mdx
wrapping-up.mdx
your-first-race-condition-test.mdx
index.md