Skip to content

Instantly share code, notes, and snippets.

@simonwoo
Last active October 22, 2016 20:15
Show Gist options
  • Select an option

  • Save simonwoo/c0fd2420447d507cad09 to your computer and use it in GitHub Desktop.

Select an option

Save simonwoo/c0fd2420447d507cad09 to your computer and use it in GitHub Desktop.

前端测试: 单元测试和集成测试。 单元测试的难点如何在多个浏览器中确保同一段JS代码正确。 e2e或者端到端(end-to-end)或者UI测试是一种测试方法,它用来测试一个应用从头到尾的流程是否和设计时候所想的一样。简而言之,它从一个用户的角度出发,认为整个系统都是一个黑箱,只有UI会暴露给用户。 Protractor是一个又AngularJS团队编写的库,它是一个队WebDriverJS的包装,同时Jasmine在这里被指定用来测试,真是太爽了。

Reference:

TODO:

  • Karma的原理
  • Protactor的原理

angular提供两个测试工具: Karma和Protactor。 Karma是一个单元测试框架,Protactor是端到端测试框架。 karma是一个允许你在多个真实的浏览器中执行Javascript的工具。它的主要目的是使测试驱动的开发更加容易,快速和有趣。 karma不是一个测试框架,也不是一个断言的库。它仅仅启动你所选择的浏览器实例,加载你指定的文件,使用测试框架将浏览器中测试执行的结果反馈到终端。Karma支持的测试框架插件主要有:

  • Jasmine
  • Mocha
  • Qunit
  • ... 开始时,Karma会自动读取工程目录下的karma.conf.js文件,格式如下:
// Karma configuration

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: [
    './src/**/*.js',
    './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: {
  },


  // test results reporter to use
  // possible values: 'dots', 'progress'
  // available reporters: https://npmjs.org/browse/keyword/karma-reporter
  reporters: ['progress'],

  // 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: ['PhantomJS'],

  // Continuous Integration mode
  // if true, Karma captures browsers, runs the tests and exits
  singleRun: false
  });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment