⬆️ ⬇️

FireUnit: Javascript Unit Testing Extension

Unit tests are something you never have time for. And if there is time, then there is no desire. And finally, if there is time and desire, then there will definitely be some asshole who will find how to take your time and discourage any desire to do anything at all ... Yes, it’s hard for the customer to explain what unit tests are and why they are needed. But nevertheless, I want to make a small review of the new plugin for Firefox, which allows your javascript to be unit-tested. To be perfectly accurate, this is an extension for Firebug - the favorite tool of javascript developers.

So, those who do not own the theory of unit testing go to teach materiel, and with the rest we will consider the simplest unit tests:



// true/false -

fireunit.ok( true, " !" );

fireunit.ok( false, " !" );

//

//

fireunit.compare(

" .",

" ",

" ?"

);

// ,

fireunit.reCompare(

/ .* ./,

" .",

" , ."

);

//

fireunit.testDone();




After running the test, we get the following results:



image

')

The feature of emulating browser events turned out to be quite useful:



// FireUnit

var input = document.getElementsByTagName("input")[0];

fireunit.mouseDown( input );

fireunit.click( input );

fireunit.focus( input );

fireunit.key( input, "a" );




Now there is no need, rushing headlong over the page and clicking on everything that clicks or clicks before ...



Another convenience that the programmer’s heart cannot touch is the splitting of tests into files and the launch of tests with a batch (in a crowd, in Russian):



// ,

fireunit.runTests("test2.html", "test3.html");

// ,

// . .

fireunit.testDone();




And here is the result:



image



The truth must be said about some of the underage in this plugin. When running several tests from different files, it is necessary that these files are located in the same directory as the file executing the batch test. To run the tests, you must have an Http server locally deployed. If the previous offer hasn't told you anything, then change the profession try adding fireunit.forceHttp () to make sure your server is ready to handle http requests.



if (fireunit.forceHttp())

{

fireunit.runTests(

"example1.html",

"example2.html"

);

}




In general, FireUnit is quite handy in javascript. Use on health.



useful links



FireUnit Examples



Developer Blog



Download FireUnit

Source: https://habr.com/ru/post/51423/



All Articles