パラメータ化(データ駆動)テストは、同じテストロジックを複数の入力セットと期待値で実行する — 各ケースに対してテストを重複させることを避けます。多くのシナリオ(エッジケースを含む)を簡潔にテストするのが容易になります。
問題:重複されたテスト
Without parameterization, testing many input/output cases means COPYING the test:
test('add 2+3', () => expect(add(2,3)).toBe(5));
test('add 0+0', () => expect(add(0,0)).toBe(0));
test('add -1+1', () => expect(add(-1,1)).toBe(0));
→ lots of near-identical, repetitive tests (tedious, hard to maintain)
パラメータ化テスト — 1つのテスト、複数のケース
test.([
[, , ],
[, , ],
[-, , ],
[, , ],
])(, {
((a, b)).(expected);
});
