Hi list, With the very latest SVN trunk of script.aculo.us having all sorts of nice unit testing thanks to efforts of Jon Tirsen (and some make-it- look-good additions from Michael Schuerig) a very nice framework for (more or less pragmatic) in-browser unit testing of JavaScript (and HTML!) has come in to place (it''s still to be considered quite alpha, but it basically works). For some working code on this, get the latest script.aculo.us trunk from SVN (as of this message revision 1966) and fire up test/ inplaceeditor_unit.html in Firefox and watch the magic. A second unit test file is test/test.html. So, how to use...? Basically, besides including unittest.js and unittest.css, you''ll need to create a new ''Test.Unit.Runner'' object that will automatically execute all included tests: new Test.Unit.Runner({ setup: function() { with(this) { // optional, do setup stuff }}, teardown: function() { with(this) { // optional, do teardown stuff }}, // example test (all functions starting with ''test'' are considered, well, tests) testBlah: function() { with(this) { // do something ... assertEqual(expected, actual, "optional message"); // see unittest.js for more asserts // do more, assert more... waitForAjax(function() { // helper for ajax calls (because they''re asynchronous), waits for 1 second // asserts ... }); }} }, "id_of_test_log_container"); You''ll also need an empty div that you reference to, this empty div will be filled with a table containing nicely listed details about the test run. When trying this out, be sure to try to set some conditions so that they fail! Please comment on this, what would be good additions, what do you want to see coming? Also, the script.aculo.us trunk (and prototype, of course) could need more unit tests.. *hint* Thomas
A live demo is available at: http://script.aculo.us/playground/unittest/test/test.html and http://script.aculo.us/playground/unittest/test/inplaceeditor_unit.html Thomas Am 02.08.2005 um 23:22 schrieb Thomas Fuchs:> Hi list, > > With the very latest SVN trunk of script.aculo.us having all sorts > of nice unit testing thanks to efforts of Jon Tirsen (and some make- > it-look-good additions from Michael Schuerig) a very nice framework > for (more or less pragmatic) in-browser unit testing of JavaScript > (and HTML!) has come in to place (it''s still to be considered quite > alpha, but it basically works). > > For some working code on this, get the latest script.aculo.us trunk > from SVN (as of this message revision 1966) and fire up test/ > inplaceeditor_unit.html in Firefox and watch the magic. A second > unit test file is test/test.html. > > So, how to use...? > > Basically, besides including unittest.js and unittest.css, you''ll > need to create a new ''Test.Unit.Runner'' object that will > automatically execute all included tests: > > new Test.Unit.Runner({ > setup: function() { with(this) { > // optional, do setup stuff > }}, > teardown: function() { with(this) { > // optional, do teardown stuff > }}, > // example test (all functions starting with ''test'' are > considered, well, tests) > testBlah: function() { with(this) { > // do something ... > assertEqual(expected, actual, "optional message"); > // see unittest.js for more asserts > // do more, assert more... > waitForAjax(function() { // helper for ajax calls > (because they''re asynchronous), waits for 1 second > // asserts ... > }); > }} > }, "id_of_test_log_container"); > > You''ll also need an empty div that you reference to, this empty div > will be filled with a table containing nicely listed details about > the test run. > > When trying this out, be sure to try to set some conditions so that > they fail! > > Please comment on this, what would be good additions, what do you > want to see coming? > Also, the script.aculo.us trunk (and prototype, of course) could > need more unit tests.. *hint* > > Thomas > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >