We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
单元测试是一种软件测试,其测试软件的各个单元或组件。目的是验证软件代码每个单元是否按照预期执行。单元测试由开发人员在应用程序的开发(编码阶段)中完成。单元测试隔离一段代码并验证其正确性。一个单元可能是单个功能,方法,过程,模块或对象。
API
推荐:单元测试和其他测试手段一起使用
我们使用Vue-Test-Utils这个Vue.js官方的单元测试实用工具库,来编写VUE应用中的单元测试。
Vue.js
VUE
这里,我们默认已经通过VUE的脚手架生成了项目,那么我们集成unit-jest插件就可以了。
unit-jest
vue add @vue/unit-jest
单元测试的文件:
// tests/unit/example.spec.js import { shallowMount } from '@vue/test-utils' import HelloWorld from '@/components/HelloWorld.vue' describe('HelloWorld.vue', () => { it('renders props.msg when passed', () => { const msg = 'new message' const wrapper = shallowMount(HelloWorld, { propsData: { msg } }) expect(wrapper.text()).toMatch(msg) }) })
单元测试的组件:
<!--scr/components/HellowWorld.vue--> <template> <div class="hello-world">msg is :{{msg}}</div> </template> <script> export default { name: 'hello-world', data() { return {} }, props: { msg: { type: String, default: 'this is props msg' } } } </script>
此时,执行下面的命令行即可:
yarn run test:unit 或者 npm run test:unit
这个时候,你就可以在控制台上看到测试用例正在跑~
The text was updated successfully, but these errors were encountered:
No branches or pull requests
单元测试是什么
单元测试是一种软件测试,其测试软件的各个单元或组件。目的是验证软件代码每个单元是否按照预期执行。单元测试由开发人员在应用程序的开发(编码阶段)中完成。单元测试隔离一段代码并验证其正确性。一个单元可能是单个功能,方法,过程,模块或对象。
为什么做单元测试
单元测试的好处
API
有基本了解单元测试的坏处
VUE项目中使用单元测试
我们使用Vue-Test-Utils这个
Vue.js
官方的单元测试实用工具库,来编写VUE
应用中的单元测试。安装
这里,我们默认已经通过
VUE
的脚手架生成了项目,那么我们集成unit-jest
插件就可以了。编写简单测试用例
单元测试的文件:
单元测试的组件:
此时,执行下面的命令行即可:
这个时候,你就可以在控制台上看到测试用例正在跑~
参考资料
The text was updated successfully, but these errors were encountered: