Adventures In JavaScript Testing

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Adventures In JavaScript Testing - Presentation Transcript

    1. Thomas Fuchs Adventures 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 for funny 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 TO AUTOMATICALLY TEST JAVASCRIPT!"
    10. all of this is pure FUD
    11. unit testing javascript
    12. s from B orrow nit Test::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) => PASS assertEqual(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) => FAIL assertNotEqual(1,’1’) => FAIL does not compare type
    23. assertMatch(expected, actual) assertMatch(/a/,’a’) => PASS assertMatch(/a/,’bab’) => PASS assertMatch(/a/,’b’) => FAIL assertMatch(/^moo$/,’moo’) => PASS
    24. assertIdentical(expected, actual) assertIdentical(‘a’,’a’) => PASS assertIdentical(1,’1’) => FAIL compares type
    25. assertNotIdentical(expected, actual) assertNotIdentical(‘a’,’a’) => FAIL assertNotIdentical(1,’1’) => PASS compares type
    26. assertType(expected, actual) assertType(String,’a’) => PASS assertType(Number,1) => PASS assertType(Array,[1,2]) => PASS checks for a specific 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 and fails/passes on that
    30. info(message) Displays arbitrary messages in the "Message" column of the test result
    31. assertXYZ(params, message)
    32. "WELL, WHAT ABOUT FUNCTIONS 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. launches web server 2. controls browsers WEBrick lists results SUCCESS FAILURE 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 definitions (add more!)
    44. $ script/plugin install http://dev.rubyonrails.org/svn/rails/plugins/javascript_test
    45. …and if something breaks?
    46. ≈ Firebug sliced bread http://www.flickr.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 all browsers you want to support
    53. get a setup that doesn‘t suck
    54. Source: http://www.flickr.com/photos/icathing/26603225/
    55. + + 2 VMs: IE 6 IE 7
    56. + + one machine to rule them all
    57. #prototype (freenode) and Rails Spinoffs Google Group

    + Thomas FuchsThomas Fuchs, 4 months ago

    custom

    554 views, 1 favs, 0 embeds more stats

    Automatic JavaScript unit testing with Prototype's more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 554
      • 554 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 12
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories