• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Javascript Unit Testing
 

Javascript Unit Testing

on

  • 1,993 views

 

Statistics

Views

Total Views
1,993
Views on SlideShare
1,986
Embed Views
7

Actions

Likes
2
Downloads
18
Comments
0

1 Embed 7

http://www.slideshare.net 7

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Javascript Unit Testing Javascript Unit Testing Presentation Transcript

    • Javascript Unit Testing Jakub Suder <jakub.suder@gmail.com> http://psionides.jogger.pl
    • Różne biblioteki
        • jsUnitTest
      new Test.Unit.Runner({ testCalculatorAdd: function() { with (this) { var calc = new Calculator(); assertEqual(4, calc.add(2, 2)); } } });
    • Różne biblioteki
        • JSSpec
      describe(&quot;Calculator&quot;, function() { with(this) { it(&quot;should add numbers&quot;, function() { var calc = new Calculator(); calc.add(2, 2).should(equal(4)); }); } });
    • Różne biblioteki
        • JSpec
      describe 'Calculator' it 'should add numbers' var calc = new Calculator calc.add(2, 2).should.equal 4 end end
    • Różne biblioteki
        • jqUnit
        • unittest
        • YUItest
        • jsUnit
        • FireUnit
        • QUnit
        • RhinoUnit
        • ...
    • Blue Ridge
        • plugin Rails
        • Screw.Unit
        • Smoke
        • Rhino
        • Env.js
    • Blue Ridge
      • ./script/plugin install
      • git://github.com/relevance/blue-ridge.git
      • ./script/generate blue_ridge
      • ./script/generate javascript_spec event
      • rake spec:javascripts [TEST=event]
      • rake js:shell
    • Blue Ridge
      • /
      • |- spec
      • |
      • |- javascripts
      • |
      • |- event_spec.js
      • |- utils_spec.js
      • |- spec_helper.js
      • |- ...
      • |- fixtures
      • |- event.html
      • |- utils.html
      • |- ...
    • Blue Ridge (Screw.Unit)
      • // utils_spec.js
      • require(&quot;spec_helper.js&quot;);
      • require(&quot;../../public/javascripts/utils.js&quot;);
      • Screw.Unit(function() {
      • describe(&quot;Utils&quot;, function() {
      • it(&quot;does something&quot;, function() {
      • expect(&quot;hello&quot;).to(equal, &quot;hello&quot;);
      • });
      • });
      • });
    • Blue Ridge (Screw.Unit)
      • expect(something).to(equal, expected)
      • expect(something).to_not(equal, expected)
      • ... be_true / be_false
      • be_null / be_undefined
      • have_length, n
      • be_empty
      • match, 'str'
      • match, /regexp/
      • be_gt / be_lt / be_gte / be_lte, val
      • Screw.Matchers[&quot;be_visible&quot;] = { ... }
    • Blue Ridge (Smoke)
      • mock(something).should_receive('method').
      • with_arguments(&quot;x&quot;, 1).exactly('once').
      • and_return(0)
      • stub(something, 'method').and_return(2)
      • stub(something, 'field').and_set_to(3)
    • Blue Ridge
      • // fixtures/utils.html (w skrócie)
      • <html>
      • <head>
      • <script type=&quot;text/javascript&quot;
      • src=&quot;../../../vendor/plugins/blue_ridge
      • /lib/blue_ridge.js&quot;></script>
      • </head>
      • <body>
      • <!-- Put any HTML fixture elements here. --> </body>
      • </html>
    • Blue Ridge
        • wyniki testu - przeglądarka:
    • Blue Ridge
        • wyniki testu - konsola:
      $ rake spec:javascripts TEST=event Running event_spec.js with fixture 'fixtures/event.html'... ........................... 27 test(s), 0 failure(s) 0.453 seconds elapsed
    • Blue Ridge $ rake js:shell ================================================= Rhino JavaScript Shell To exit type 'exit', 'quit', or 'quit()'. ================================================= - loaded env.js - sample DOM loaded - jQuery-1.2.6 loaded ================================================= Rhino 1.7 release 2 PRERELEASE 2008 07 28 js> $('body').append(&quot;<p>asd</p>&quot;) [object Object] js> $('p').length 1 js>
    • Blue Ridge
      • Uwagi:
        • Rhino + env.js ≠ przeglądarka
        • bugi w env.js
        • Smoke.reset() nie resetuje :-)