I amQiana , WELCOME.

NO TRY , NO HIGH

Test Runner--Karma 简单介绍

  • Karma?

    官网是这么定义的:

    On the AngularJS team,we rely on testing and we always seek better tools to make our life easier.
    That's why we created Karma- a test runner that fits all our needs.
    

    简单的说,Karma是用来干什么的呢?

    The main goal for Karma is to bring a productive testing environment to developers.
    The environment being one where they don't have to set up loads of configurations,but rather a place
    where developers can just write the code and get instant feedback from their tests.
    Because getting quick feedback is what makes you productive and creative.
    

    总结下,Karma是一个测试运行器,它可以将开发,CI,产品等不同环境下测试所需要的配置管理起来。从而使程序员只专注于写测试本身。Karma可以是测试驱动开发更加的简单,高效,有趣。
    需要注意的是,Karma不是测试框架,也不是断言库。它只是能够启动一个HTTP服务器,依赖于测试框架,生成你可能已经知道的测试运行器的HTML文件。


  • Karma(Testacular)

Karma在2013年前也叫Testacular.

Alt text

如果你现在去搜索Testacular,会链接到Karma资源处。

qq

  • Karma Install

    Karma runs on Node.js and is available as an NPM package.

  • Install Karma:

    $ npm install karma –save-dev

  • Install plugins that your project needs:

    $ npm install karma-jasmine karma-chrome-launcher …… –save-dev


  • configuration

    $ karma init my.conf.js

  • Browsers

    the browsers configuration setting is empty by default.

  • Preprocessors

  • $ npm install -g istanbul
  • npm install karma karma-coverage –save-dev
  • Plugins
  • In fact, all the existing preprocessors, reporters, browser launchers and frameworks are also plugins.
  • Installation (npm install karma-(plugin name) –save-dev)
  • Loading Plugin

  • start

  • Run karma:

    $ ./node_modules/karma/bin/karma start my.conf.js

  • Install Karma Commandline Interface:

    $ npm install -g karma-cli


$ karma start my.conf.js

  • Grunt-Karma

    npm install grunt –save-dev
    npm install grunt-karma –save-dev


  • Karma优缺点

    - Run tests from browsers or PhantomJS
    - Run on multiple clients at once
    - Supports multiple JavaScript test frameworks
    - Auto-run tests on save
    - Reporters
    - Plugins
    - Supported by IntelliJ and WebStorm
    - Open source
    ---
    - No plugin for Eclipse (yet)
    - No history of previous test results
    
  • 更多地JavaScript Test Runner