fast-check
https://gyazo.com/0f88c371e2bf6e22f360b30ffc3e8c81
fast-checkによってOSSのバグが見つかった実例
特別な設定は不要そう
普通に、test(..)の中でfc.assertを呼べば良い
global settings
生成するケース数とか
code:ts
fc.property(...arbitraries, (...args) => {});
例
code:ts
fc.assert(
fc.property(fc.string(), fc.string(), fc.string(), (a, b, c) => {
return contains(a + b + c, b);
}),
);
3つのstring値を生成してる
Command pattern的なシステムとかreducerを使う系のもののテストという感じmrsekut.icon
テスト用にもCommandとその事前条件を定義しておき、事前条件を満たすものだけを、ランダムに投げていくテスト
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で作るんだ
introduction
core-blocks
properties.md
advanced
fake-data.md
fuzzing.md
model-based-testing.md
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