background preloader

TESTS UNITAIRES et FONCTIONNELS

Facebook Twitter

Testing JavaScript with Jest. Unit testing. Wallaby - Integrated Continuous Test Runner for JavaScript. Tests unitaires et intégration continue – De geek à directeur technique. Je vais vous parler de deux notions qui sont assez connexes, et que certaines personnes ont tendance à mélanger un peu.

Tests unitaires et intégration continue – De geek à directeur technique

Les tests unitaires Le but des tests unitaires est d’automatiser les tests de non-régression. Quand on développe un logiciel, on peut facilement faire des modifications sans se rendre compte qu’elles introduisent des bugs dans certains cas particuliers. C’est ce qu’on appelle des bugs de régression, en ce sens qu’on introduit de nouveaux bugs à la suite d’une évolution fonctionnelle.

Comme il n’est pas humainement possible de tester systématiquement tous les cas d’utilisation possible, ces bugs peuvent se retrouver déployés en production, avec tous les problèmes que cela comporte. Une des notions importantes, quand on fait du développement, est de savoir que plus un bug est détecté tôt, plus il sera facile à corriger.

L’intégration continue Comme je le disais en introduction, certaines personnes confondent les tests unitaires avec le processus d’intégration continue. Best of JavaScript. Testacular (now Karma) - JavaScript Test Runner. Karma - a Javascript Test Runner. Karma - a Javascript Test Runner Michael G Bielski, Karma is a test runner for JavaScript that runs on Node.js.

Karma - a Javascript Test Runner

It is very well suited to testing AngularJS or any other JavaScript projects. Using Karma to run tests using one of many popular JavaScript testing suites (Jasmine, Mocha, QUnit, etc.) and have those tests executed not only in the browsers of your choice, but also on the platform of your choice (desktop, phone, tablet.) Karma is highly configurable, integrates with popular continuous integration packages (Jenkins, Travis, and Semaphore) and has excellent plugin support. Website: Tested: v0.10 running on NodeJS 0.8.19 running on Windows 7 Professional 64-bitLicense and Pricing: Open SourceSupport: User mailing list/group on Google Groups ( and tagged questions on Stack Overflow ( and Installation The recommended installation location of Karma is in your global node_modules directory.

Configuration Before you run Karma you must configure it. Do you want to use Require.js? Plugins. Karma - Spectacular Test Runner for Javascript. CasperJS, a navigation scripting and testing utility for PhantomJS and SlimerJS. CasperJS et les tests fonctionnels - Lors de mes récentes sessions de veille, je me suis intéressé à différents outils permettant de faciliter la mise en place de tests fonctionnels.

CasperJS et les tests fonctionnels -

À la différence des tests unitaires qui sont mis en place individuellement sur chaque projet, les tests fonctionnels sont encore peu implémentés. Et pourtant, ils demeurent tout aussi importants. La distinction pourrait se résumer en deux phrases bien choisies : Unit testing makes sure you are using quality ingredients. Functional testing makes sure your application doesn’t taste like crap. Présentation À l’heure actuelle, CasperJS est sans nul doute l’outil le plus utilisé et le projet le plus suivi pour mettre en place des tests fonctionnels sur des applications web. How to test JavaScript with Mocha — The Basics. Framework de test Mocha. Mocha (JavaScript framework) Mocha is a JavaScript test framework for Node.js programs, featuring browser support, asynchronous testing, test coverage reports, and use of any assertion library.

Mocha (JavaScript framework)

Mocha can be used with most JavaScript assertion libraries, including: should.jsexpress.jschaibetter-assertunexpected $ npm install -g mocha $ mkdir test var assert = require("assert")describe('Foo', function(){ describe('#getBar(value)', function(){ it('should return 100 when value is negative') // placeholder it('should return 0 when value is positive', function(){ assert.equal(0, Foo.getBar(10)); }) })}) $ mocha . 1 test complete (1ms) For asynchronous testing, invoke the callback, and Mocha will wait for completion. describe('Foo', function(){ describe('#bar()', function(){ it('should work without error', function(done){ var foo = new Foo(128); foo.bar(done); }) })})

Mocha - the fun, simple, flexible JavaScript test framework. Jasmine (JavaScript testing framework) Jasmine aims to be easy to read.

Jasmine (JavaScript testing framework)

A simple hello world test looks like the code below, where describe() describes a suite of tests and it() is an individual test specification. The name "it()" follows the idea of behavior-driven development and serves as the first word in the test name, which should be a complete sentence. Usage follows syntax similar to that of RSpec. The code below tests this function function helloWorld() { return 'Hello world! ' and verifies that its output is indeed the text "Hello world! ". Jasmine Documentation.