Testem

Testem is a Node-based test runner. It is run from the command line and opens up a simple interface to view test results. Testem will automatically detect changes to JavaScript files and execute tests on the fly, providing instant feedback during the unit testing phase. Testem also has a very handy feature that allows multiple browsers to connect to the same testem instance. This allows us to connect an instance of Chrome, Firefox, IE, Opera, Safari, QupZilla, or pretty much any type of browser to the same testem runner. Testem will rerun our tests in each and every browser and present a summary view as follows:

Testem also has a continuous integration setting that can be used on build servers. More info can be found at the GitHub repository (https://github.com/airportyh/testem).

Testem can be installed through Node with the following command (Note that you may need to prefix it with sudo on a Linux-based system.):

npm install -g testem

Testem, by default, will try to load any JavaScript files in the current directory, parse them for any tests, and then run them when a browser is connected. Testem therefore creates a simple HTML page in memory, and serves this page to our browsers. We will need to configure testem by creating a simple testem.json file in our test directory as follows:

{ 
    "framework": "jasmine2", 
    "src_files": [ 
        "node_modules/jquery/dist/jquery.js", 
        "node_modules/jasmine-jquery/lib/jasmine-jquery.js", 
        "html_spec/HtmlTests.spec.js" 
    ] 
}

This file is a simple JSON format file that specifies two properties, framework and src_files. The framework property indicates that we are using "jasmine2" as our test framework, and the source_files property includes some extra JavaScript files that are needed for our tests, along with the html_spec/HtmlTests.spec.js file itself. With this testem.json file in place, we are able to run our test suite. Note that even though we are specifying jasmine2 as our framework, we are able to use Jasmine 3.0 and higher.

Testem has a number of powerful configuration options that can be specified in the configuration file. Be sure to head over to the GitHub repository for more information.

Note that testem is a good choice for unit testing, but is not a good choice for integration or acceptance testing. The nature of the framework means that Testem builds an HTML page on the fly based on our configuration file. During integration testing, we generally want HTML pages to be created by a web server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.239.148