Testing applications using Jasmine

You can test your web applications using Jasmine

JavaScript unit test development tools

Your workbench contains a set of tools to create automated unit tests for JavaScript-based applications. These tools allow you to:
  • Create new JavaScript unit test projects, which can reference other web projects in the workspace to discover JavaScript files and artifacts that can be unit tested.
  • Add unit-testing support to existing web projects.
  • Use Jasmine framework as your testing runtime. The workbench now bundles Jasmine, but you can use any Jasmine version; simply specify the path to your library and the workbench includes it in your project.
  • Create test files based on Jasmine spec structure. These test files can reference any JavaScript file in the workspace.
  • Use the standard JavaScript development tools already present in the workbench to either discover JavaScript functions or create test code from the templates available.
  • Create test runners and discover the test files as well as your JavaScript files under test that are in the same test project or spanning in different projects across the workspace. This test runner creation wizard adds the required artifacts to quickly run the tests as soon as the test runner is created.
  • Deploy and run the tests on a server. Whether you are using static or dynamic web projects, you can deploy the unit test application to Web Preview server, WebSphere® Application Server Liberty Profile, a full WebSphere Application Server profile, or any other server.
  • Share your test projects with other developers and version it using a software configuration management application, such as Rational Team Concert™ or Git.
Jasmine is a framework that allows you to create JavaScript unit tests based on behavior-driven development (BDD) that makes clear the intentions of each test suite always targeting a clean, easy-to-read implementation. A typical Jasmine test is composed of:
  1. Test file: Also called a spec file. This is a plain JavaScript file that holds the test code.
  2. Test suite: Also called the spec. The spec is defined by the function it describes. The spec contains a description of the test suite as well as a callback function that in turn contains the setup, scenarios, and tear down of the tests. A spec file can hold as many test suites as the developer wants.
  3. 3. Test case: Defined by the function it. This is placed inside the describe function, meaning that this belongs to a test suite. This is also defined with a meaningful description and a callback function, which hold the logic of the test case. This callback function also can receive a function called done that is used to set the test as complete, which is very useful for asynchronous tests.
  4. 4. Test runner: Also called spec runner. This is a regular HTML file that loads the Jasmine files as well as the Spec files and API files. This HTML triggers the test execution once it is loaded by the web browser.

For more information about Jasmine, see Jasmine: Behavior-Driven JavaScript Documentation/