Wednesday, April 1st, 2009

JsContext to make your JsUnitTest look purty

Category: JavaScript, Testing

Christian Johansen was sick of testNewUserWithClownShoesShouldSqueak code in his unit tests, so he took some inspiration from the Ruby Shoulda and Context frameworks and wrote JsContext which allows you to write:

javascript

  1. new Test.Unit.Runner({
  2.     "A new User": JsContext({
  3.         "with clown shoes": JsContext({
  4.  
  5.             "should squeak": function() { with(this) {
  6.  
  7.                 // ...
  8.             }},
  9.  
  10.             // ...more tests and/or contexts
  11.         }),
  12.  
  13.         "without clown shoes": JsContext({
  14.  
  15.             "should not squeak": function() { with(this) {
  16.  
  17.                 // ...
  18.             }},
  19.  
  20.             // ...more tests and/or contexts
  21.         }),
  22.  
  23.         // ...more tests and/or contexts
  24.  
  25.     }),
  26.  
  27.     // ...more tests and/or contexts
  28. }, { testLog: "testlog" });

Using this, the test runner will label tests a lot more readable; where you may have been used to “testNewUserWithClownShoesShouldSqueak” you now get “A new user with clown shoes should squeak”.

We are looking to standardize on a testing framework for Bespin. What do you like to use?

Posted by Dion Almaer at 4:14 am
2 Comments

+++--
3.3 rating from 18 votes

2 Comments »

Comments feed TrackBack URI

Hmmm… http://ajaxian.com/archives/improved-readability-for-javascript-unit-tests

Comment by bogphanny — April 1, 2009

This looks interesting. The big problem I found though is standardizing the output of the tests. You notice they don’t show any examples of that on the JsContext website. Take a look at FireUnit for solving this problem:

http://bigbangtechnology.com/blog/post/writing_tests_first_in_fireunit

Writing tests isn’t the problem with most JavaScript users. It’s integrating with the tools that they use every day.

Comment by camwest — April 1, 2009

Leave a comment

You must be logged in to post a comment.