测试框架是为编写和运行测试提供结构和工具的工具——测试组织、断言、运行、报告等。每种语言都有流行的框架(Jest、JUnit、pytest 等)。它们使测试变得实用且标准化。
测试框架提供的功能
text
✓ TEST STRUCTURE — define tests and group them (test/it, describe/suite)
✓ ASSERTIONS — check expected outcomes (expect, assert) with helpful matchers
✓ TEST RUNNER — discover, run all tests, and report pass/fail results
✓ SETUP/TEARDOWN — run code before/after tests (beforeEach, afterEach) for shared setup
✓ MOCKING — create test doubles (mocks, stubs, spies) for dependencies
✓ REPORTING — clear output, failure details, coverage integration
示例(Jest)
js
(, {
calc;
( { calc = (); });
(, {
(calc.(, )).();
});
(, {
( calc.(, )).();
});
});
