Unit-Testing With Jasmine

Unit-Testing With Jasmine

第38回 HTML5とか勉強会資料

32f242f75b63e7174b493446de54a6b8?s=128

Yuya Saito

April 26, 2013
Tweet

Transcript

  1. 5.

    AGeNda WHaT Is bDD? f WHaT Is JAsMiNe? , GEt

    MOrE OuT Of JAsMiNe ^ MAkE JAsMiNe mORe USeFul i
  2. 7.

    g Testability is an inherent quality of good design. You

    can have testability and still have bad design, sure, but you cannot have good design without testability. Think of the tests as small sample use cases - examples of using your code - if testing is hard, it means using the code is hard.
  3. 12.

    6 QUeStIoNs On tDD:  ·ͣͲ͔͜Β࢝ΊΕ͹Α͍ͷ͔  ͳʹΛςετ͢Ε͹Α͍ͷ͔  ͳʹΛςετ͢Δඞཁ͕ͳ͍ͷ͔

     ͭͷ΋ͷʹରͯ͠Ͳͷఔ౓ςετ͢Ε͹Α͍ͷ͔  ςετΛͳΜͱݺ΂͹Α͍ͷ͔  ςετ͕ࣦഊͨ͠ཧ༝ΛͲ͏ཧղ͢Ε͹Α͍ͷ͔ v v v v v v v v v v v v v v v v v v v v v v v v v v
  4. 13.

    DAn NOrTh ANsWeRs: v v v v v v v

    v v v v v v v v v v v v v v v v v v v ͜Ε͔Β࡞੒͠Α͏ͱ͢ΔϓϩάϥϜʹظ଴͞ΕΔ ʮৼΔ෣͍ʯ ΍ ʮ੍໿৚݅ʯ ɺ ͭ·Γ ʮ ཁٻ࢓༷ʯ ʹ ͍ۙܗͰɺ ࣗવݴޠΛซه͠ͳ͕ΒςετίʔυΛ هड़͢Δ͜ͱ͕ղܾ΁ͷۙಓͩͱߟ͑ͨɻ
  5. 14.

    IN SHoRt: v v v v v v v v

    v v v v v v v v v v v v v v v v v v  ΞϓϦέʔγϣϯશମͰ͸ͳ͘ɺ খ͘͞ɺ ͭͷ͜ͱͷΈςετ͢Δ  ςετΛจষͷΑ͏ʹهड़͢Δ
  6. 17.

    JAsMiNe Is: v v v v v v v v

    v v v v v v v v v v v v v v v v +BWB4DSJQUͷͨΊͷ ϏϔΠϏΞۦಈͷςετϑϨʔϜϫʔΫ
  7. 18.

    JAsMiNe Is: v v v v v v v v

    v v v v v v v v v v v v v v v v ͋Δ࢓༷ 4QFD ʹରͯ͠ɺ ίʔυ͕ ͲΜͳৼΔ෣͍Λ͢Δ΂͖͔Λදݱ͢ΔͷΛ खॿ͚ͯ͘͠ΕΔπʔϧ
  8. 20.
  9. 24.

    Suite describe("Hello world", function(){ it("says hello to the world", function(){

    expect(helloWorld().toEqual("Hello world!")); }); });
  10. 27.
  11. 36.

    describe("employee", function(){ var employee; beforeEach(function(){ employee = new Employee; });

    it("has a name", function(){ expect(employee.name.toBeDefined()); }); it("has a role", function(){ expect(employee.role.toBeDefined()); }); });
  12. 37.

    describe("employee", function(){ var employee; beforeEach(function(){ employee = new Employee; });

    it("has a name", function(){ expect(employee.name.toBeDefined()); }); it("has a role", function(){ expect(employee.role.toBeDefined()); }); });
  13. 38.
  14. 39.
  15. 40.

    describe("an async spec", function () { var r, fetchDone; it("fetchFilter",

    function () { runs(function () { model.fetch(opts) .done(function(data) { r = data; fetchDone = true; }); }); waitsFor(function() {return fetchDone;}, "never completed", 5000); runs(function () { expect(r[0].gender).toBeDefined(); }); }); });
  16. 42.
  17. 45.

    JAsMiNe SPiEs Are: v v v v v v v

    v v v v v v v v v v v v v v v v v ؔ਺ʹ੒Γ୅Θͬͯɺ ͦͷؔ਺͕ԿΛ͍ͯ͠Δͷ͔Λ஌Βͤͯ͘ΕΔɻ
  18. 46.

    JAsMiNe SPiEs Are: v v v v v v v

    v v v v v v v v v v v v v v v v v  ݺͼग़͞Ε͔ͨͲ͏͔  Կճݺͼग़͞Εͨͷ͔  ͲΜͳҾ਺Ͱݺͼग़͞Ε͔ͨ
  19. 49.

    describe("an async spec", function () { var r, fetchDone; it("fetchFilter",

    function () { runs(function () { model.fetch(opts) .done(function(data) { r = data; fetchDone = true; }); }); waitsFor(function() {return fetchDone;}, "never completed", 5000); runs(function () { expect(r[0].gender).toBeDefined(); }); }); });
  20. 50.

    describe("an async spec", function() { var async = new AsyncSpec(this);

    var r; async.beforeEach(function(done){ // simulate async stuff and wait 10ms setTimeout(function(){ model.fetch(opts).done(function(data) { r = data; }); done(); }, 10); }); async.it("fetchFilter", function(done) { expect(res[0].gender).toBeDefined(); }); });
  21. 64.

    g If Edison had a needle to find in a

    haystack, he would proceed at once with the diligence of the bee to examine straw after straw until he found the object of his search. I was a sorry witness of such doings, knowing that a little theory and calculation would have saved him ninety per cent of his labor.