测试与调试
150 道练习
150 道测试练习覆盖单元测试、断言、Mock 与 TDD 流程,培养可测试的代码设计习惯。
- 1
什么是 Automated 测试?
Identify 核心 purpose 的 automated 测试 in software development.
单选题 入门 - 2
单元对比 Integration 测试
Distinguish 之间单元测试 and integration 测试通过作用域.
单选题 简单 - 3
排列-Act-Assert 模式
Recognize three phases 的 AAA 测试模式.
单选题 简单 - 4
测试 Suite and 测试情况
理解关系之间测试 suites and 测试情况.
单选题 入门 - 5
Assertion 基础
Identify 什么 assertion 做 in 测试.
单选题 入门 - 6
Jest 测试() 函数
理解基础 Jest 测试() 函数 signature.
单选题 简单 - 7
expect() Matchers
Identify 有效 Jest matchers for expect().
单选题 简单 - 8
Purpose 的 Mocks
理解为什么 mocks 是 used in 单元测试.
单选题 中等 - 9
Spy 对比 Stub
Differentiate 之间 spies and stubs in 测试.
单选题 中等 - 10
TDD Red-Green-Refactor
Identify three phases 的 TDD cycle.
单选题 中等 - 11
100% Coverage Meaning
理解什么 100% code coverage actually guarantees.
单选题 中等 - 12
测试异步函数
Know 如何 测试 asynchronous 函数 in Jest.
单选题 中等 - 13
beforeEach 对比 beforeAll
Distinguish 之间 beforeEach and beforeAll Hook.
单选题 中等 - 14
Snapshot 测试 Use 情况
理解当 snapshot 测试是 大多数 useful.
单选题 中等 - 15
E2E 测试 Tools
Identify popular 端-到-端测试 tools.
单选题 简单 - 16
测试 Pyramid Layers
理解结构的 测试 pyramid.
单选题 中等 - 17
Parameterized 测试
理解 benefit 的 parameterized (表-driven) 测试.
单选题 中等 - 18
CI 测试 Purpose
理解 role 的测试 in continuous integration.
单选题 简单 - 19
React 测试库
理解 philosophy 的 React 测试库.
单选题 中等 - 20
BDD 对比 TDD
Distinguish 之间 BDD and TDD 方法.
单选题 中等 - 21
Predict toBe Result
Predict outcome 的 Jest toBe assertion.
预测输出 入门 - 22
Predict toEqual 使用对象
Predict whether toEqual 通过 for two identical 对象.
预测输出 简单 - 23
Predict toBe 使用对象
Predict whether toBe 通过 for two identical-looking 对象.
预测输出 简单 - 24
Predict toContain Result
Predict result 的 toContain assertion on 数组.
预测输出 简单 - 25
Predict toBeNull
Predict result 的 toBeNull assertion.
预测输出 入门 - 26
Predict toBeUndefined
Predict result 的 toBeUndefined assertion.
预测输出 入门 - 27
Predict toBeTruthy
Predict result 的 toBeTruthy assertion on 0.
预测输出 简单 - 28
Predict toHaveLength
Predict result 的 toHaveLength assertion.
预测输出 简单 - 29
Predict toThrow
Predict result 的 toThrow assertion.
预测输出 中等 - 30
Predict toBeGreaterThan
Predict result 的 toBeGreaterThan assertion.
预测输出 简单 - 31
Predict Mock 返回值
Predict 输出的 mocked 函数 call.
预测输出 中等 - 32
Predict Mock Call 数量
Predict 数字的 次数 mock 是 called.
预测输出 中等 - 33
Predict Spy Call 实参
Predict 实参 recorded 通过 spy.
预测输出 中等 - 34
Predict toMatchObject
Predict result 的 toMatchObject assertion.
预测输出 中等 - 35
Predict toBeFalsy
Predict result 的 toBeFalsy assertion on 空字符串.
预测输出 简单 - 36
Predict toBeInstanceOf
Predict result 的 toBeInstanceOf assertion.
预测输出 简单 - 37
Predict toHaveBeenCalledWith
Predict result 的 toHaveBeenCalledWith assertion.
预测输出 中等 - 38
Predict 字符串 toMatch
Predict result 的 regex toMatch assertion.
预测输出 中等 - 39
Predict toBeLessThan
Predict result 的 toBeLessThan assertion.
预测输出 简单 - 40
Predict Nested toEqual
Predict result 的 deep equality 检查使用 nested 对象.
预测输出 中等 - 41
Fill: 测试() 函数
完整 Jest 测试函数语法.
填空题 入门 - 42
Fill: expect Matcher
完整 Jest assertion 使用正确 matcher.
填空题 入门 - 43
Fill: 描述块
完整 Jest 描述块 语法.
填空题 入门 - 44
Fill: beforeEach Hook
完整 Jest Hook 那个运行之前每个测试.
填空题 简单 - 45
Fill: afterEach Hook
完整 Jest Hook 那个运行之后每个测试.
填空题 简单 - 46
Fill: jest.fn()
完整 code 到创建 mock 函数.
填空题 简单 - 47
Fill: mockReturnValue
完整 code 到设置 mock's 返回值.
填空题 中等 - 48
Fill: TDD 首先步骤
完整首先步骤的 TDD cycle.
填空题 中等 - 49
Fill: Coverage Tool
完整 Jest coverage flag.
填空题 简单 - 50
Fill: 异步/等待测试
完整异步测试语法.
填空题 中等 - 51
Fill: toContain
完整 matcher 到检查数组 membership.
填空题 简单 - 52
Fill: toEqual
完整 matcher for deep equality.
填空题 简单 - 53
Fill: toThrow
完整 matcher 到检查如果函数 throws.
填空题 中等 - 54
Fill: jest.spyOn
完整 code 到 spy on 方法.
填空题 中等 - 55
Fill: toMatchSnapshot
完整 snapshot 测试 matcher.
填空题 中等 - 56
Fill: 测试.每个
完整 parameterized 测试语法.
填空题 中等 - 57
Fill: toBeDefined
完整 matcher 到检查值 是定义.
填空题 简单 - 58
Fill: 测试.skip
完整 code 到 skip 测试.
填空题 简单 - 59
Fill: toHaveBeenCalled
完整 matcher 到检查 mock 是 called.
填空题 中等 - 60
Fill: toHaveBeenCalledTimes
完整 matcher 到检查 call 数量.
填空题 中等 - 61
Mistake: Missing Assertion
查找 mistake in 测试那个 lacks assertion.
找错误 入门 - 62
Mistake: toBe on 对象
查找 mistake using toBe for 对象 comparison.
找错误 简单 - 63
Mistake: Missing 等待
查找 mistake in 异步测试 missing 等待.
找错误 中等 - 64
Mistake: toThrow Called Directly
查找 mistake in toThrow assertion.
找错误 中等 - 65
Mistake: Shared 可变状态
查找 mistake 使用 shared 状态之间测试.
找错误 中等 - 66
Mistake: 不 Restoring Mock
查找 mistake 使用 unrestored spy.
找错误 中等 - 67
Mistake: 测试 Floating 点
查找 mistake 使用 floating-点 comparison.
找错误 中等 - 68
Mistake: 多个 Assertions
查找 mistake 使用测试多个 unrelated things.
找错误 中等 - 69
Mistake: 错误 Matcher Name
查找 mistake 使用不正确 matcher.
找错误 入门 - 70
Mistake: Missing 做回调
查找 mistake 使用回调-based 异步测试.
找错误 中等 - 71
Mistake: 测试 Implementation
查找 mistake 使用测试内部 implementation.
找错误 中等 - 72
Mistake: 异步 in beforeEach
查找 mistake 使用异步设置.
找错误 中等 - 73
Mistake: Blindly 更新 Snapshot
查找 mistake 使用 snapshot 更新.
找错误 中等 - 74
Mistake: Meaningless 测试 Name
查找 mistake 使用 poor 测试描述.
找错误 简单 - 75
Mistake: Mocking 也 Much
查找 mistake 使用 over-mocking.
找错误 中等 - 76
Mistake: Comparing NaN
查找 mistake 使用 NaN comparison.
找错误 中等 - 77
Mistake: Chasing 100% Coverage
查找 mistake 使用 coverage-focused 方法.
找错误 中等 - 78
Mistake: 测试 Depends on 顺序
查找 mistake 使用顺序-dependent 测试.
找错误 中等 - 79
Mistake: Using toBe for 数组
查找 mistake 使用数组 comparison.
找错误 简单 - 80
Mistake: Hardcoded 时间 in 测试
查找 mistake 使用时间-dependent 测试.
找错误 中等 - 81
概念: 为什么测试?
检查理解的 值的 automated 测试.
概念检查 入门 - 82
概念: 测试类型 Hierarchy
检查理解的 测试 hierarchy.
概念检查 简单 - 83
概念: Isolation in 单元测试
检查理解的 测试 isolation.
概念检查 简单 - 84
概念: TDD Benefits
检查理解的 TDD advantages.
概念检查 中等 - 85
概念: 当到 Mock
检查理解的 appropriate mocking 场景.
概念检查 中等 - 86
概念: Coverage 类型
检查理解的 不同 coverage metrics.
概念检查 中等 - 87
概念: E2E 测试 Cost
检查理解的 E2E 测试 trade-offs.
概念检查 中等 - 88
概念: Integration 测试作用域
检查理解的 什么 integration 测试验证.
概念检查 简单 - 89
概念: 查询通过 Role
检查理解的 React 测试库 查询.
概念检查 中等 - 90
概念: Snapshot Files
检查理解的 snapshot file management.
概念检查 中等 - 91
概念: CI 测试速度
检查理解的 CI 测试 optimization.
概念检查 中等 - 92
概念: Given-当-然后
检查理解的 BDD 场景结构.
概念检查 中等 - 93
概念: 测试 Independence
检查理解的 为什么测试应该是 independent.
概念检查 简单 - 94
概念: 测试 Doubles 类型
检查理解的 不同测试双 类型.
概念检查 中等 - 95
概念: 测试 Promise
检查理解的 Promise 测试方法.
概念检查 中等 - 96
概念: jsdom 环境
检查理解的 jsdom 测试环境.
概念检查 中等 - 97
概念: Shallow 对比 Deep 渲染
检查理解的 shallow 对比 deep 组件渲染.
概念检查 中等 - 98
概念: AAA 模式 Benefit
检查理解的 排列-Act-Assert 模式.
概念检查 简单 - 99
概念: Flaky 测试
检查理解的 flaky 测试.
概念检查 中等 - 100
概念: 测试 as Documentation
检查理解的 测试 as living documentation.
概念检查 简单 - 101
单元测试用途
什么是单元测试?
单选题 入门 - 102
集成测试
集成测试验证什么?
单选题 简单 - 103
E2E 测试
什么是端到端(E2E)测试?
单选题 简单 - 104
测试金字塔
什么是测试金字塔?
单选题 简单 - 105
Jest test 函数
Jest 中 test() 函数做什么?
单选题 入门 - 106
expect 函数
Jest 中 expect() 做什么?
单选题 入门 - 107
toBe 与 toEqual
toBe 与 toEqual 有何区别?
单选题 简单 - 108
describe 块
Jest 中 describe() 做什么?
单选题 入门 - 109
beforeEach 用途
beforeEach 做什么?
单选题 简单 - 110
Mock 用途
测试中什么是 mock?
单选题 简单 - 111
Spy 与 Stub
Spy 与 Stub 有何不同?
单选题 中等 - 112
TDD 循环
TDD 的三个步骤是什么?
单选题 简单 - 113
异步测试
如何在 Jest 中测试异步函数?
单选题 简单 - 114
快照测试
快照测试做什么?
单选题 中等 - 115
覆盖率指标
代码覆盖率衡量什么?
单选题 简单 - 116
测试隔离
为什么测试隔离重要?
单选题 简单 - 117
参数化测试
什么是参数化测试?
单选题 简单 - 118
BDD 风格
测试中什么是 BDD?
单选题 中等 - 119
React Testing Library
什么是 React Testing Library?
单选题 中等 - 120
断言抛出
如何测试函数抛出错误?
单选题 简单 - 121
Mock 模块
jest.mock() 做什么?
单选题 中等 - 122
测试替身类型
测试替身有哪些类型?
单选题 中等 - 123
CI 测试
测试在 CI/CD 中的角色是什么?
单选题 简单 - 124
测试命名
好的测试命名约定是什么?
单选题 简单 - 125
不稳定测试
什么是不稳定测试及为什么有害?
单选题 中等 - 126
DOM 测试
什么是 DOM 测试?
单选题 中等 - 127
测试设置文件
什么是 Jest 设置文件?
单选题 中等 - 128
测试类型
软件测试的主要类型有哪些?
单选题 中等 - 129
变异测试
什么是变异测试?
单选题 中等 - 130
测试重构
何时应重构测试?
单选题 中等 - 131
toBe 通过
预测输出。
预测输出 入门 - 132
toBe 失败
预测输出。
预测输出 入门 - 133
toEqual 对象
预测输出。
预测输出 简单 - 134
toBe 对象失败
预测输出。
预测输出 简单 - 135
toHaveLength
预测输出。
预测输出 简单 - 136
toContain
预测输出。
预测输出 简单 - 137
toThrow
预测输出。
预测输出 简单 - 138
toBeTruthy
预测输出。
预测输出 入门 - 139
toBeFalsy
预测输出。
预测输出 入门 - 140
not 修饰符
预测输出。
预测输出 简单 - 141
Mock 调用
预测输出。
预测输出 简单 - 142
Mock 调用次数
预测输出。
预测输出 简单 - 143
Mock 返回值
预测输出。
预测输出 简单 - 144
async/await
预测输出。
预测输出 简单 - 145
beforeEach 运行
预测输出。
预测输出 简单 - 146
test.each
预测输出。
预测输出 中等 - 147
字符串匹配器
预测输出。
预测输出 简单 - 148
对象键
预测输出。
预测输出 中等 - 149
解析 Promise
预测输出。
预测输出 中等 - 150
拒绝 Promise
预测输出。
预测输出 中等
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。