By: Dustin Butler
What is Jasmine?
Jasmine API includes features such as:
* A more natural BDD syntax for organizing the test logic than JUnit style assertion test frameworks
* Asynchronous testing
* Easy to create custom matchers
* Ability to share or isolate behaviors between tests within a spec encapsulating parts of your spec.
* Continuous integration support
Many available libraries add additional functionality to the already robust Jasmine API. These include jasmine-ui, jasmine-features, and jasmine-jQuery for testing through the DOM, or Jasmine-species for changing the grammatical nature of the tests.
Its syntax and test suite implementation are similar to Ruby’s RSpec framework, which takes a BDD approach to writing the tests. This syntax is different from the jUnit, QUnit, and FlexUnit style assertion frameworks that tend to verify the code from the inside out. Jasmine syntax is more narrative. It describes the behavior the code is supposed to support. It is written similar to the way an agile user story is written. And testing happens from the outside in. More on this later.
What kinds of tests should I use Jasmine for?
What is a unit test?
At its core, a unit test is a program (known as a test case, or test specification) that isolates and tests a specific and small functional unit of source code. Never test too many pieces of code at one time. And, unlike with an integration test, do not use unit tests to test more than one system at a time.
Why write unit tests?
You probably already have an understanding of the value of unit testing your code. But if you are still skeptical, here are a few reasons that I hope convince you to write them.
* Unit tests demonstrate the code functions as designed.
* Unit tests can be run every time you compile your code or do a build. This consistency is especially useful when a developer checks in a change that inadvertently affects code in another area of the application.
* Running a suite of unit tests is faster than manual testing.
* Unlike manually testing your application by clicking through the fields in your browser, you are guaranteed that the tests run the same way every time. That is not to say that unit testing makes system testing in the browser unnecessary, but it does ensure a certain level of confidence in the code.
* Writing unit tests helps developers write better code. Whether you chose to write the unit tests before the code is written or after, the tests often persuade the developer to write code that is better structured, easier to maintain, and “composable” (in other words, modular and usually stateless).
* Unit tests provide documentation for the source code. These tests describe the interface to your code.
* Over time, you acquire a comprehensive suite of tests against the code base.
* Uncovering bugs before going to QA is cheaper.
... to read more articles, visit http://sqa.fyicenter.com/art/