1:安装karma

y@y:~$ npm install --global karma

2:安装karma插件

y@y:~$  npm install --global karma-jasmine karma-chrome-launcher

运行Karma:

y@y:~$ .npm-packages/lib/node_modules/karma/bin/karma start
INFO [karma]: Karma v0.12.32 server started at http://localhost:9876/

3:安装karma,命令行插件

y@y:~$ npm install -g karma-cli

测试:

y@y:~$ karma --version
Karma version: 0.12.
y@y:~$ karma start
INFO [karma]: Karma v0.12.32 server started at http://localhost:9876/

4:配置Karma

y@y:angular-test$ karma init my-karma.conf.js

Which testing framework do you want to use ?
Press tab to list possible options. Enter to move to the next question.
> jasmine Do you want to use Require.js ?
This will add Require.js plugin.
Press tab to list possible options. Enter to move to the next question.
> no Do you want to capture any browsers automatically ?
Press tab to list possible options. Enter empty string to move to the next question.
> Chrome
> What is the location of your source and test files ?
You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js".
Enter empty string to move to the next question.
> *.js
WARN [init]: There is no file matching this pattern. > test/*Spec.js
> Should any of the files included by the previous patterns be excluded ?
You can use glob patterns, eg. "**/*.swp".
Enter empty string to move to the next question.
> Do you want Karma to watch all the files and run the tests on change ?
Press tab to list possible options.
> yes Config file generated at "/home/y/my_note/nodejs/angular-test/my-karma.conf.js". y@y:angular-test$ ll
总用量
drwxrwxr-x y y 5月 : ./
drwxrwxr-x y y 5月 : ../
drwxrwxr-x y y 5月 : app/
drwxrwxr-x y y 5月 : bower_components/
drwxrwxr-x y y 5月 : .idea/
-rw-rw-r-- y y 5月 : my-karma.conf.js
drwxrwxr-x y y 5月 : test/
y@y:angular-test$

5:修改项目下面的my-karma.conf.jsp配置文件,将需要的js文件引入:

    // list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.min.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/js/*.js',
'test/*Spec.js'
],

6:进行运行测试:

@y:angular-test$ karma start my-karma.conf.js
INFO [karma]: Karma v0.12.32 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 39.0. (Linux)]: Connected on socket cz6gdNTkD5A0FyfLAAAA with id
Chrome 39.0. (Linux): Executed of SUCCESS (0.021 secs / 0.016 secs)

Install and use Karma的更多相关文章

  1. AngularJS中使用Karma单元测试初体验

    ■ 搭建karma测试环境 → 创建app和test文件夹→npm install karma --save-dev→npm install karma-jasmine --save-dev→npm ...

  2. Karma和Jasmine自动化单元测试

    从零开始nodejs系列文章,将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的引擎,是目前速度最快的Javascript引擎.chrome浏 ...

  3. karma+seajs

    下面的介绍以karma能正常运行为前提,看karma系列文章:http://www.cnblogs.com/laixiangran/tag/Karma/ 目录结构 步骤 安装 npm install ...

  4. karma+requirejs

    下面的介绍以karma能正常运行为前提,看karma系列文章:http://www.cnblogs.com/laixiangran/tag/Karma/ 目录结构 步骤 安装 npm install ...

  5. jasmine+karma 自动化单元测试

    测试的必须性 相信大家都知道测试的必要性,测试先行的概念.不过,写了这么多年的代码,除了之前用java的时候写过一些测试用例,还真的很少写过前端的测试用例,或者做一些自动化测试.感觉做单元测试还是很有 ...

  6. Karma和Jasmine自动化单元测试——本质上还是在要开一个浏览器来做测试

    1. Karma的介绍 Karma是Testacular的新名字,在2012年google开源了Testacular,2013年Testacular改名为Karma.Karma是一个让人感到非常神秘的 ...

  7. 在本地创建angular-ui/bootstrap项目

    在本地创建完整的angular-ui/Bootstrap项目 git clone the repo, then switch to the tag you want,then use grunt bu ...

  8. angularjs自动化测试系列之karma

    angularjs自动化测试系列之karma karma test with jasmine 更好的利用工具是为了让生活更美好. 需要安装的东西: npm install karma -g mkdir ...

  9. karma单元测试入门

    学习angularjs,都会遇到karma单元测试,可是初学者面对复杂的测试配置往往不知从何入手,下面我们将抛开angularjs,单独使用两个js文件,完成一次测试入门. 0,karma原理

随机推荐

  1. 谷歌 google

    google Google是搜索引擎名,也是一家美国上市公司名称.Google公司于1998年9月7日以私有股份公司的形式创立,以设计并管理一个互联网的搜索引擎.Google公司的总部称作“Googl ...

  2. 自定义UINavigationItem的两种方法以及相应的隐藏方法

    第一种: UIImage *searchimage=[UIImage imageNamed:@"search.png"]; UIBarButtonItem *barbtn=[[[U ...

  3. mybatis使用时org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):的错误

    最近在使用mybatis时,出现了 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 这 ...

  4. Resizable 2th click not working

    here's a simple solution.  just destroy the resizable function, then rebuild it. try { $("#div& ...

  5. Unity3D基础学习之AssetBundle 资源包创建与加载

    前几天做了AssentBundle的例子,遇到了问题,在论坛上问了三天都没人解答,最后在一个朋友的帮助下解决了.下面介绍AssentBundle. AssetBundles让你通过WWW类流式加载额外 ...

  6. Android常用ProgressDialog设置

    public static ProgressDialog initDialog(Context context) { ProgressDialog progressDialog = new Progr ...

  7. C++获得系统路径

    源码: [cpp] view plaincopy #include <Shlobj.h> #include <stdio.h> #include <locale.h> ...

  8. uploadify上传大文件时出现404错误

    出现这个错误的话一般是IIs限制了文件大小.IIS7下的默认设置限制了上传大小.这个时候Web.Config中的大小设置也就失效了.具体步骤:1.打开IIS管理器,找到Default Web Site ...

  9. Java基础知识强化92:日期工具类的编写和测试案例

    1. DateUtil.java,代码如下: package cn.itcast_04; import java.text.ParseException; import java.text.Simpl ...

  10. Atlas mysql的读写分离和负载均衡<转>

    mysql的读写分离和负载均衡 http://my.oschina.net/superbigfu/blog/178134