Showing posts with label Unit-Test. Show all posts
Showing posts with label Unit-Test. Show all posts

Wednesday, November 12, 2014

Javascript - Unit Testing (with Jasmine) on a browser

This post is about unit testing Javascript using Jasmine using a browser.

1. Get Jasmine here.
2. Download and unpack -- mine is in ~/app/jasmine
3. Project directory should be something like:


4. Edit the SpecRunner.html file to include the source files and the test files:


5. The test file should not run the "require" code:


6. Run the tests by viewing on the browser:

Done.

To run tests on nodejs instead of via a browser, see this earlier post.

Javascript - Unit Testing (with Jasmine) using NodeJS

Here's how to implement unit testing (with Jasmine and Node) for a class defined earlier:


Source files in subfolder "src" and test files in subfolder "spec". All test files must end with ".spec.js". Execute the test like so:


Done.

To run tests via a browser instead, see this other post.

Perl - Unit Testing

Here's a screenshot how unit testing can be implemented in Perl for the class we defined earlier.

The testing file should be in the ./t subfolder. Execute the tests like so:

Done.