手把手教你如何安装和使用Karma-Jasmine
2015-06-04 08:27
295 查看
注意:本文中出现的资料链接、karma的插件安装等,均可能需要翻$墙后才能正确执行。
Jasmine是一个Javascript的测试工具,在Karma上运行Jasmine可完成Javascript的自动化测试、生成覆盖率报告等。本文不包含Jasmine的使用细节,这几天我会写一篇Jasmine的入门文章,有兴趣的朋友到时候可以看一下。
下载之后,双击 node-v0.12.4-x64.msi 运行并安装,这个就不赘述了, 不断下一步即可, 当然最好将目录改一下。
图1(选择安装内容,默认即可):
View Code
执行命令:
图17(执行命令后,在配置文件coverageReporter节点中指定的dir中,我们将找到生成的覆盖率报告,karma-coverage还生成了一层子文件夹,对应于执行测试的浏览器+版本号+操作系统版本):
Karma-runner安装步骤:https://karma-runner.github.io/0.12/intro/installation.html
Karma config file: http://karma-runner.github.io/0.8/config/configuration-file.html
Karma files:http://karma-runner.github.io/0.8/config/files.html
Karma和Jasmin自动化单元测试:http://blog.fens.me/nodejs-karma-jasmine/
AngularJS的UnitTest:https://docs.angularjs.org/guide/unit-testing
Jasmine是一个Javascript的测试工具,在Karma上运行Jasmine可完成Javascript的自动化测试、生成覆盖率报告等。本文不包含Jasmine的使用细节,这几天我会写一篇Jasmine的入门文章,有兴趣的朋友到时候可以看一下。
步骤一:安装Node.JS(版本:v0.12.4, windows-64)
Karma是运行在Node.js之上的,因此我们首先要安装Node.js。到 https://nodejs.org/download/ 下载你系统所需的NodeJS版本,我下载的是windows-64位的msi版。下载之后,双击 node-v0.12.4-x64.msi 运行并安装,这个就不赘述了, 不断下一步即可, 当然最好将目录改一下。
图1(选择安装内容,默认即可):
// Karma configuration // Generated on Fri May 29 2015 19:30:26 GMT+0800 (中国标准时间) module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine'], // list of files / patterns to load in the browser files: [ '../TestFiles/jasmineTest.js', '../TestFiles/test.js' ], // list of files to exclude exclude: [ ], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { '../TestFiles/test.js':'coverage' }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['progress','coverage'], coverageReporter:{ type:'html', dir:'../TestFiles/coverage/' }, // web server port port: 9876, // enable / disable colors in the output (reporters and logs) colors: true, // level of logging // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG logLevel: config.LOG_INFO, // enable / disable watching file and executing tests whenever any file changes autoWatch: true, // start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: ['Chrome'], // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits singleRun: false }); };
View Code
执行命令:
karma start karma.conf.js
图17(执行命令后,在配置文件coverageReporter节点中指定的dir中,我们将找到生成的覆盖率报告,karma-coverage还生成了一层子文件夹,对应于执行测试的浏览器+版本号+操作系统版本):
参考资料:
Karma-runner:http://karma-runner.github.io/0.12/index.htmlKarma-runner安装步骤:https://karma-runner.github.io/0.12/intro/installation.html
Karma config file: http://karma-runner.github.io/0.8/config/configuration-file.html
Karma files:http://karma-runner.github.io/0.8/config/files.html
Karma和Jasmin自动化单元测试:http://blog.fens.me/nodejs-karma-jasmine/
AngularJS的UnitTest:https://docs.angularjs.org/guide/unit-testing
相关文章推荐
- 百度地图经纬度 转换到 腾讯地图/Google地图 对应经纬度
- Linux 定时任务
- 杭电1018
- Spark 资源调度及任务调度
- http及其请求方法(一)
- Nginx配置文件详细说明
- Reorder List -- leetcode
- POI2013 Bytecomputer
- 聊聊Web App、Hybrid App与Native App的设计差异
- Android PackageManager基础知识
- 常用语句地址以及数据库中计算角色数量
- 机器学习中的内核方法 李政轩的视频笔记
- 为什么是kafka?
- datatable前端传递参数与返回值格式说明
- Robotium获取TextView的Text
- ginx平台初探
- js深拷贝和浅拷贝
- 工作流介绍
- C# 并行编程 之 PLINQ 规约操作和聚合函数
- 九度 斐波那契数列