JS Unite-Test

JS Unite-Test

QUnit

основные фичи:

  • Легкая в изучении и использование
  • Удобно тестировать локальный код на js
  • Возможность тестирования асинхронный код

Полезные ссылки:

JsTestDriver

 основные фичи:

  • Минимум настроек: только номер порта для сервера и пути к файлам браузеров (Firefox, Chrome, Safari, Internet Explorer и Opera) на локальном компьютере
  • Запуск сервера и браузеров для тестирования прямо из IDE
  • Простейший конфигурационный файл для запуска тестов (прописывается только URL тестового сервера и список необходимых javascript-файлов)
  • Ручной запуск модульных тестов через меню Run
  • Автоматический запуск модульных тестов при каждом изменении javascript-файлов

Полезные ссылки:

Download JsTestDriver

download link: http://code.google.com/p/js-test-driver/downloads/list

Project Configuration JsTestDriver

All used examples are available on Github.

Unless specified otherwise, js-test-driver expects configuration in current working directory in a file named jsTestDriver.conf.

At minimum, the configuration file must contain:

  • list of JavaScript files under test in section load,
  • list of JavaScript files containing test cases in section test.

The configuration file would look like this:

 

load:
  - src/Utilities.js
  - src/Core.js
  - src/Main.js
  
test:
  - src-test/TestsUtils.js
  - src-test/*.js
 
Сonfiguration parameters:
Parameters
Discription
server
Specifies the default location of the server.
load

List of files to load to browser before the test can be run. We support globing with *. The files are loaded in the same order as specified in the configuration file or alphabetically if using globing.You can declare external scripts by adding the http address of the script as a loadedable item.

test
A list of test sources to run.
exclude
Never load this file. Used in conjunction with globing and load. Useful saying load everything except these files.
serve
Load static files (images, css, html) so that they can be accessed on the same domain as jstd.

Running Tests - Command Line

Start Server

 

Use the command java -jar JsTestDriver.jar --port <PORT_NUMBER> to start the server. The parameter port is mandatory, the server will listen on it.

java -jar JsTestDriver.jar --port 42442
Capture Browser

Open the browser and put http://<servers ip address>:<PORT_NUMBER>/capture into URL bar.

http://127.0.0.1:42442/capture

The browser is now captured. Its top should have green color and contain something like this:

JsTestDriver
Last:1323466357645 | Next:1975 | Server:Waiting...
Start Both Server and Browsers

If you do not want to manually open each browser and edit its url, use the parameter --browser <browser 1>,<browser 2>,..., <browser n>. It will start each listed browser and fill correct capture URL into it.

java -jar JsTestDriver.jar --port 42442 --browser "C:\Program Files (x86)\Mozilla Firefox\firefox.exe",C:\Users\AppData\Local\Google\Chrome\Application\chrome.exe,"C:\Program Files\Internet Explorer\iexplore.exe

Run Tests

The simplest possible way to run tests is the command java -jar JsTestDriver.jar --server <servers address:port> --tests all .
It will read jsTestDriver.conf file in the current directory, send all configured files to the browser and run all tests.

java -jar JsTestDriver.jar --server http://127.0.0.1:42442 --tests all

All command line options are available on the projects wiki page.

Simple Testing

Create simplest possible test case

Example test

Logging

 

All command line options are available on the projects wiki page.