Adventures In JavaScript Testing

  • View
    2.581

  • Download
    0

Embed Size (px)

DESCRIPTION

Automatic JavaScript unit testing with Prototype's JavaScript testing facilities.

Text of Adventures In JavaScript Testing

  • 1.Thomas FuchsAdventures in JavaScript Testing

2. http://script.aculo.us/thomas 3. traditional javascript testing 4. alert(please use me only where appropriate!); 5. why? 6. "JavaScript is this thing forfunny mouse trails, right?" 7. "BUT You CAN't DEBUG JavaScript!" 8. "WE DON'T NEED NO STINKIN' TESTS FOR TEN LINES OF CODE!" 9. "ANYWAY, THERE IS NO WAY TOAUTOMATICALLY TEST JAVASCRIPT!" 10. all of this ispure FUD 11. unit testing javascript 12. s from B orrow nitTest::U 13. include unittest.js (requires Prototype) 14. a DIV is required for containing the test results (defaults to "testlog") 15. create a new instance of Test.Unit.Runner 16. this will excute all methods starting with "test" 17. assert away! 18. (syntax strangeness for more convenience when calling assertions) 19. assert(expression)assert(true) => PASS assert(false) => FAIL assert(2*2==4) => PASS 20. assertEqual(expected, actual) assertEqual(a,a) => PASS assertEqual(a,b) => FAIL assertEqual(1,1) => PASSassertEqual(1,1) => PASS does not compare type 21. assertEnumEqual(expected, actual) assertEnumEqual([1,2],[1,2]) => PASS assertEqual([1,2],[1,2]) => FAIL assertEqual does not compare enum contents 22. assertNotEqual(expected, actual) assertNotEqual(a,a) => FAIL assertNotEqual(a,b) => PASS assertNotEqual(1,1) => FAILassertNotEqual(1,1) => FAIL does not compare type 23. assertMatch(expected, actual)assertMatch(/a/,a) => PASS assertMatch(/a/,bab) => PASSassertMatch(/a/,b) => FAIL assertMatch(/^moo$/,moo) => PASS 24. assertIdentical(expected, actual) assertIdentical(a,a) => PASSassertIdentical(1,1) => FAILcompares type 25. assertNotIdentical(expected, actual) assertNotIdentical(a,a) => FAILassertNotIdentical(1,1) => PASScompares type 26. assertType(expected, actual) assertType(String,a) => PASSassertType(Number,1) => PASS assertType(Array,[1,2]) => PASSchecks for a specic constructor 27. assertRaise(exceptionName, method) assertRaise(ElementDoesNotExistError,function(){new Effect.Opacity(invalid-element)} );related effects.js code 28. assertRespondsTo(method, obj) 29. assertVisible(element) assertNotVisible(element) also checks if any parent elements are hidden andfails/passes on that 30. info(message)Displays arbitrary messages in the "Message" column of the test result 31. assertXYZ(params, message) 32. "WELL, WHAT ABOUTFUNCTIONS THAT RUN ASYNCHRONOUSLY?" 33. wait(milliseconds, method)should be last statement in the test (but can be nested) 34. Benchmarking 35. "WELL, NICE. BUT IT'S TEDIOUS TO RUN ALL THOSE TESTS MANUALLY!" 36. rake to the rescue 37. rake test:javascripts 38. javascript_test plugin 39. rake test:javascripts 1. launchesweb server 2. controls browsers WEBricklists results SUCCESSFAILURE ERROR 3. run tests 40. $ script/generate javascript_test muhaha exists test/javascript create test/javascript/muhaha_test.html 41. just add your tests 42. (symlink required: app/test/javascript/assets to app/vendor/plugins/javascript_test/assets) 43. Browser denitions(add more!) 44. $ script/plugin install http://dev.rubyonrails.org/svn/rails/plugins/javascript_test 45. and if something breaks? 46. Firebug sliced breadhttp://www.ickr.com/photos/teagrrl/78941282/ 47. Firebug Debugger 48. Firebug know your Ajax 49. Safari Web Inspector 50. Safari Debugging 51. Microsoft Script Debugger for IE http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx 52. Test with allbrowsers you want to support 53. get a setup thatdoesnt suck 54. Source: http://www.ickr.com/photos/icathing/26603225/ 55. + + 2 VMs:IE 6IE 7 56. + + one machine to rule them all 57. #prototype (freenode)and Rails Spinoffs Google Group