Skip to content

Commit 484023a

Browse files
BDD
1 parent 1378152 commit 484023a

File tree

16 files changed

+92
-313
lines changed

16 files changed

+92
-313
lines changed

13-自动化测试&mock数据/README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,35 @@
66
2. jest
77

88
## 2. TDD (Test-Driven Development) 测试驱动开发
9+
多用于单元测试
10+
1. 先写测试再写代码
11+
2. 一般结合单元测试使用,是白盒测试
12+
3. 重点在测试代码
13+
4. 安全感低
14+
5. 速度快
915

10-
`Red-Green Development`
16+
比如此案例用 "shallowMount"
1117

18+
`Red-Green Development`
1219
1. 编写测试用例
1320
2. 运行测试,测试用例无法通过测试
1421
3. 编写代码,使测试用例通过测试
1522
4. 优化代码,完成开发
1623
5. 重复上述步骤
1724

1825
**优势:**
19-
2026
1. 长期减少回归BUG
2127
2. 代码质量更好(组织、可维护性)
2228
3. 测试覆盖率高
2329
4. 错误测试代码不容易出现
2430

2531

2632
## 3. BDD (Behavior Driven Development) 行为驱动开发
27-
28-
29-
33+
多用于集成测试
34+
1. 先写代码再写测试
35+
2. 一般结合集成测试使用,是黑盒测试
36+
3. 测试重点在 UI(DOM)
37+
4. 安全感高
38+
5. 速度慢
39+
40+
比如此案例用 "mount"

13-自动化测试&mock数据/jest-vue/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ testPathIgnorePatterns
66

77
修复eslint语法
88

9-
npm run lint --fix
9+
npm run lint --fix
10+
11+
## 配置 vuex
12+
npm install vuex --save

13-自动化测试&mock数据/jest-vue/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

13-自动化测试&mock数据/jest-vue/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
"build": "vue-cli-service build",
88
"lint": "vue-cli-service lint",
99
"test:unit": "vue-cli-service test:unit --watch",
10+
"test:integration": "vue-cli-service test:unit --watch",
1011
"test:cov": "vue-cli-service test:unit --coverage"
1112
},
1213
"dependencies": {
1314
"core-js": "^2.6.5",
14-
"vue": "^2.6.10"
15+
"vue": "^2.6.10",
16+
"vuex": "^3.1.1"
1517
},
1618
"devDependencies": {
1719
"@vue/cli-plugin-babel": "^3.8.0",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { mount } from '@vue/test-utils'
2+
import { findTestWrapper } from '@/utils/testUtils'
3+
import TodoList from '@/containers/TodoList/TodoList'
4+
import store from '@/store'
5+
6+
it(`
7+
1. 用户会在 header 输入框输入内容
8+
2. 用户会点击回车按钮
9+
3. 列表项应该增加用户输入内容的列表项
10+
`, () => {
11+
// 不能用 shallowMount 渲染,shallowMount 用于单元测试
12+
// const wrapper = shallowMount(TodoList)
13+
// 此处要使用 mount 渲染组件树
14+
const wrapper = mount(TodoList, { store }) // 传入 store
15+
const inputElem = findTestWrapper(wrapper, 'header-input').at(0)
16+
const content = 'csxiaoyao'
17+
inputElem.setValue(content)
18+
inputElem.trigger('change')
19+
inputElem.trigger('keyup.enter')
20+
const listItems = findTestWrapper(wrapper, 'list-item')
21+
expect(listItems.length).toBe(1)
22+
// 因为会包含 '-' 删除按钮
23+
expect(listItems.at(0).text()).toContain(content)
24+
})

13-自动化测试&mock数据/jest-vue/src/containers/TodoList/__tests__/unit/Header.test.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

13-自动化测试&mock数据/jest-vue/src/containers/TodoList/__tests__/unit/TodoList.test.js

Lines changed: 0 additions & 107 deletions
This file was deleted.

13-自动化测试&mock数据/jest-vue/src/containers/TodoList/__tests__/unit/UndoList.test.js

Lines changed: 0 additions & 102 deletions
This file was deleted.

13-自动化测试&mock数据/jest-vue/src/containers/TodoList/__tests__/unit/__snapshots__/Header.test.js.snap

Lines changed: 0 additions & 17 deletions
This file was deleted.

13-自动化测试&mock数据/jest-vue/src/containers/TodoList/__tests__/unit/__snapshots__/HelloWorld.test.js.snap

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)