Thomas Fuchs Presentation

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

    Favorites, Groups & Events

    Thomas Fuchs Presentation - Presentation Transcript

    1. Thomas Fuchs Adventures in JavaScript testing
    2. Thomas Fuchs wollzelle script.aculo.us mir.aculo.us
    3. traditional javascript „testing“
    4. http://www.flickr.com/photos/stephendann/80555607/
    5. alert(“please use me only where appropriate!”);
    6. why?
    7. \"JavaScript is this thing for funny mouse trails, right?\"
    8. \"BUT You CAN't DEBUG JavaScript!\"
    9. \"WE DON'T NEED NO STINKIN' TESTS FOR TEN LINES OF CODE!\"
    10. \"ANYWAY, THERE IS NO WAY TO AUTOMATICALLY TEST JAVASCRIPT!\"
    11. all of this is pure FUD
    12. unit testing javascript
    13. s from orrow nit B est::U T
    14. include unittest.js (requires Prototype)
    15. a DIV is required for containing the test results (defaults to \"testlog\")
    16. create a new instance of Test.Unit.Runner…
    17. …this will excute all methods starting with \"test\"
    18. assert away!
    19. (syntax strangeness for more convenience when calling assertions)
    20. assert(expression) assert(true) => PASS assert(false) => FAIL assert(2*2==4) => PASS
    21. assertEqual(expected, actual) assertEqual(‘a’,’a’) => PASS assertEqual(‘a’,’b’) => FAIL assertEqual(1,1) => PASS assertEqual(1,’1’) => PASS does not compare type
    22. assertEnumEqual(expected, actual) assertEnumEqual([1,2],[1,2]) => PASS assertEqual([1,2],[1,2]) => FAIL assertEqual does not compare enum contents
    23. assertNotEqual(expected, actual) assertNotEqual(‘a’,’a’) => FAIL assertNotEqual(‘a’,’b’) => PASS assertNotEqual(1,1) => FAIL assertNotEqual(1,’1’) => FAIL does not compare type
    24. assertMatch(expected, actual) assertMatch(/a/,’a’) => PASS assertMatch(/a/,’bab’) => PASS assertMatch(/a/,’b’) => FAIL assertMatch(/^moo$/,’moo’) => PASS
    25. assertIdentical(expected, actual) assertIdentical(‘a’,’a’) => PASS assertIdentical(1,’1’) => FAIL compares type
    26. assertNotIdentical(expected, actual) assertNotIdentical(‘a’,’a’) => FAIL assertNotIdentical(1,’1’) => PASS compares type
    27. assertType(expected, actual) assertType(String,’a’) => PASS assertType(Number,1) => PASS assertType(Array,[1,2]) => PASS checks for a specific constructor
    28. assertRaise(exceptionName, method) assertRaise(‘ElementDoesNotExistError’, function(){ new Effect.Opacity(‘invalid-element’) } ); related effects.js code
    29. assertRespondsTo(method, obj)
    30. assertVisible(element) assertNotVisible(element) also checks if any parent elements are hidden and fails/passes on that
    31. info(message) Displays arbitrary messages in the \"Message\" column of the test result
    32. assertXYZ(params, message)
    33. \"WELL, WHAT ABOUT FUNCTIONS THAT RUN ASYNCHRONOUSLY?\"
    34. wait(milliseconds, method) should be last statement in the test (but can be nested)
    35. Benchmarking
    36. \"WELL, NICE. BUT IT'S TEDIOUS TO RUN ALL THOSE TESTS MANUALLY!\"
    37. rake to the rescue
    38. rake test:javascripts
    39. javascript_test plugin
    40. rake test:javascripts 1. launches web server 2. controls browsers WEBrick lists results SUCCESS FAILURE ERROR 3. run tests
    41. $ script/generate javascript_test muhaha exists test/javascript create test/javascript/muhaha_test.html
    42. just add your tests
    43. (symlink required: app/test/javascript/assets to app/vendor/plugins/javascript_test/assets)
    44. Browser definitions (add more!)
    45. $ script/plugin install http://dev.rubyonrails.org/svn/rails/plugins/javascript_test
    46. …and what about BDD?
    47. http://www.flickr.com/photos/sfllaw/4281980/
    48. s from orrow c B RSpe
    49. specifications
    50. add BDD methods to any object
    51. for isSomething() methods, that return a boolean
    52. should* assertations, directly on objects
    53. (\"with\" ugliness no longer required)
    54. Mapping
    55. Mixed environment can also use \"normal\" assertations
    56. …and if something breaks?
    57. ≈ Firebug sliced bread http://www.flickr.com/photos/teagrrl/78941282/
    58. Firebug Debugger
    59. Firebug know your Ajax
    60. Venkman JavaScript Debugger with omes ! C filing Pro
    61. Safari Web Inspector
    62. Safari Debugging with Drosera
    63. + http://webkit.org/
    64. Microsoft Script Debugger for IE http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx
    65. Test with all browsers you want to support
    66. get a setup that doesn‘t suck
    67. Source: http://www.flickr.com/photos/icathing/26603225/
    68. + + (+ )
    69. one machine to rule them all
    70. help and ideas welcome #prototype (freenode) and Rails Spinoffs Google Group

    + RubyOnRails_dudeRubyOnRails_dude, 3 years ago

    custom

    1957 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1957
      • 1957 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 72
    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