Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
What NOT to test in your       project
?
1describe “test” do2 it “should do nothing” do3    fail4 end5 end
1describe “test” do2 it “should do nothing” do3    fail4 end5 end
1describe “test” do2 it “should do nothing” do3    true4 end5 end
?1describe “test” do2 it “should do nothing” do3    true4 end5 end
Do youDELETEyour tests?
@davidhussmanI think that tests that never fail shouldbe deleted. If a test doesn’tcommunicate something meaningfulabout t...
@dhhI find over-testing to be mostcommon among those 1st adoptingTDD. So excited about the idea thatthey go completely over...
Don’t use Cucumberunless you live in the magic kingdomof non-coders-writing-tests(and send me some fairy dust if you are!)
@mfeathersUltimately, tests are a feedbackmechanism, and we should makeactive decisions about whatfeedback we need and when.
@unclebobmartin1 of Kent’s older wise sayings was:“Test everything that could possiblybreak.” I think that’s a pretty good...
@metayodaI would rather have 10% coveragewith 100% quality tests, than 100%coverage with lousy tests.
@joshuakerievskyTest first/after misses the point thatTDD is more about emergent designthan it is about testing. Do youprac...
@kentbeckIf I don’t typically make a mistake(...),I don’t test for it.Wish there were more examples of“what not to test”.
60@Test61public void setPrice() {62 Item item = new63    BasicItem(0.0, true);6465 assertEquals(0.0,66         item.getPri...
74@Test75public void isImported_true(){76 Item item = new77     BasicItem(0.0, true);7879   assertTrue(item.isImported());...
74@Test75public void isImported_false(){76 Item item = new77     BasicItem(0.0, false);7879   assertFalse(item.isImported(...
28public Double getPrice(){25 return price;26}2728public boolean isImported(){29  return imported;30}
2 def create_name(fname,3                 lname)4   raise “fname must be5         a String”6    unless fname.kind_of?7    ...
1 require ‘spec_helper‘2 describe Candidate do3   context ‘associations‘ do4      it { should have_many(:proposals) }5    ...
1 require ‘valid_url‘2 class Candidate < ActiveRecord::Base3   has_many :proposals45   validates :name, presence: true67  ...
1 require ‘spec_helper‘2 describe Candidates do34 let(:candidate) {double ‘candidate‘}56 before :each do7   Candidate8    ...
1Feature: Create proposal2 As a candidate3 I want to post my proposals4 So that voters can evaluate them56 Scenario:7    G...
1Scenario: Client sees tooltip for plan2 Given3    I select the ‘light‘ plan4 When5    I mouse over ‘tooltip‘6 Then7    I ...
1require ‘spec_helper‘2describe ShoppingCart do34 let(:user) {double ‘user‘}5 let(:product) {double ‘product‘}67 before :e...
100% COVERED CODE.                   LINE  OF CODE YOU COVER
PIXEL NAZI
50@Test51public void changeMarks() {52 bot.leftClickAt(view,53                  800, 508);54 addMarkAt(‘drama’, 1);5556 bo...
1 require ‘spec_helper‘2 describe AddressController do34   it ‘should calculate shipping‘ do5    get :shipping, :zipcode =...
fixturesconsideredharmful?
<- costumer                   facing           VS  backoffice ->
JAVASCRIPT?
module(MultiSelectQuizTests,{    setup: function() {        var container =           document.getElementById("qunit-fixtu...
Being goodat stupiddoesn’tcount.
WHY DOWE TEST?
Murphy’s law
PAIN
FLOW
Speed   Robustness
How muchQUALITY isENOUGH?
Bugs/1KLOC  5                    0,004  4  3  1  0      Indústria   Nasa
Cost($/LOC)                   850 900 675 450 225       5   0       Indústria     Nasa
@marickI test the high risk code thoroughly.I use up most of the remaining timetesting the medium risk code.I don’t intent...
@martinfowleryou’re doing enough testing if thefollowing is true: ■You rarely get bugs that escape  into production ■You a...
@jamesshoreSkill and discipline give us fluency.Then fluency gives us ease and joy.
LESSONSLEARNED
baby steps:grow up,the realworld is nota dojo
DRY
WET
Testjourneys
Too muchsleep()
non-deterministicor flaky testsuite
@googleIf they fail we simply run flaky tests3x (and keep statistics). Developertime is much more valuable thanserver time.
@javosantillanI see companies that don’t test realintegration until the very end. Andalso don’t test performance, leaving ...
externaldependencies:
SCALABILITY              SECURITY NON-FUNCTIONAL REQUIREMENTSPERFORMANCE              RELIABILITY
technique    vs   tool
feedback   vs  noise
Evolutionary     design       vs Guarantee ofworking software
deciding whatNOT to test isas IMPORTANTas writing tests
bring thepainforward
JOIN              the              RE-              VO-              LU-              TI-JAVASCRIPT    ON
agradecimentos:@camiloribeiro, @lucabastos, @neal4rd,@tottinge, @brownie490, @hugocorbucci,@dtsato, @p_balduino, @mauricio...
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
What NOT to test in your project
Upcoming SlideShare
Loading in …5
×

What NOT to test in your project

1,356 views

Published on

In this talk we discuss automated testing and give examples of tests we've seen (or written ourselves) that we don't believe add value to your test suite. These slides accompany a live talk so you might not get that much from them alone...

What NOT to test in your project

  1. 1. What NOT to test in your project
  2. 2. ?
  3. 3. 1describe “test” do2 it “should do nothing” do3 fail4 end5 end
  4. 4. 1describe “test” do2 it “should do nothing” do3 fail4 end5 end
  5. 5. 1describe “test” do2 it “should do nothing” do3 true4 end5 end
  6. 6. ?1describe “test” do2 it “should do nothing” do3 true4 end5 end
  7. 7. Do youDELETEyour tests?
  8. 8. @davidhussmanI think that tests that never fail shouldbe deleted. If a test doesn’tcommunicate something meaningfulabout the desing, what is it’s value?
  9. 9. @dhhI find over-testing to be mostcommon among those 1st adoptingTDD. So excited about the idea thatthey go completely overboard.
  10. 10. Don’t use Cucumberunless you live in the magic kingdomof non-coders-writing-tests(and send me some fairy dust if you are!)
  11. 11. @mfeathersUltimately, tests are a feedbackmechanism, and we should makeactive decisions about whatfeedback we need and when.
  12. 12. @unclebobmartin1 of Kent’s older wise sayings was:“Test everything that could possiblybreak.” I think that’s a pretty goodrecipe.
  13. 13. @metayodaI would rather have 10% coveragewith 100% quality tests, than 100%coverage with lousy tests.
  14. 14. @joshuakerievskyTest first/after misses the point thatTDD is more about emergent designthan it is about testing. Do youpractice emergent design?
  15. 15. @kentbeckIf I don’t typically make a mistake(...),I don’t test for it.Wish there were more examples of“what not to test”.
  16. 16. 60@Test61public void setPrice() {62 Item item = new63 BasicItem(0.0, true);6465 assertEquals(0.0,66 item.getPrice());6768 //set new price69 item.setPrice(1.0);70 assertEquals(1.0,71 item.getPrice());72}
  17. 17. 74@Test75public void isImported_true(){76 Item item = new77 BasicItem(0.0, true);7879 assertTrue(item.isImported());80}
  18. 18. 74@Test75public void isImported_false(){76 Item item = new77 BasicItem(0.0, false);7879 assertFalse(item.isImported());80}
  19. 19. 28public Double getPrice(){25 return price;26}2728public boolean isImported(){29 return imported;30}
  20. 20. 2 def create_name(fname,3 lname)4 raise “fname must be5 a String”6 unless fname.kind_of?7 String8 raise “lname must be9 a String”10 unless lname.kind_of?11 String11 end
  21. 21. 1 require ‘spec_helper‘2 describe Candidate do3 context ‘associations‘ do4 it { should have_many(:proposals) }5 end67 context ‘validations‘ do8 it { should validate_presence_of :name }910 it { should ensure_lenght_of(:phone).11 is_at_least(7).12 is_at_most(14)13 }1415 it { should_not16 allow_value(‘blah‘).for(:site) }1718 it { should19 allow_value(‘http://www.blah.com‘)20 .for(:site) }21 end22end
  22. 22. 1 require ‘valid_url‘2 class Candidate < ActiveRecord::Base3 has_many :proposals45 validates :name, presence: true67 validates :phone, :length =>8 {:in => 8..14},9 :allow_blank1011 validates :site, :url => true,12 :allow_nil => true1314end
  23. 23. 1 require ‘spec_helper‘2 describe Candidates do34 let(:candidate) {double ‘candidate‘}56 before :each do7 Candidate8 .should_receive(:find)9 .with(1).and_return(candidate)10 end1112 it ‘should find the candidate‘ do13 c = Candidate.find(1)14 c.should eql candidate15 end16end
  24. 24. 1Feature: Create proposal2 As a candidate3 I want to post my proposals4 So that voters can evaluate them56 Scenario:7 Given I am logged in8 And I am posting a proposal9 When10 I fill all fields of the proposal11 Then12 I should see a success message
  25. 25. 1Scenario: Client sees tooltip for plan2 Given3 I select the ‘light‘ plan4 When5 I mouse over ‘tooltip‘6 Then7 I should see ‘tooltip‘ content8 And9 I mouse out ‘tooltip‘10 Then11 I should not see ‘tooltip‘ content
  26. 26. 1require ‘spec_helper‘2describe ShoppingCart do34 let(:user) {double ‘user‘}5 let(:product) {double ‘product‘}67 before :each do8 Authenticator.should_receive(:auth)9 .and_return(true)10 end1112 it ‘should addProduct & getTotal‘ do13 Authenticator.auth(user)14 cart = ShoppingCart.new15 cart.add_product(product)16 cart.get_total17 end18end
  27. 27. 100% COVERED CODE. LINE OF CODE YOU COVER
  28. 28. PIXEL NAZI
  29. 29. 50@Test51public void changeMarks() {52 bot.leftClickAt(view,53 800, 508);54 addMarkAt(‘drama’, 1);5556 bot.leftClickAt(view,57 900, 508);58 addMarkAt(‘act’, 3);5960 bot.verifyTooltipAt(30, 190);61}
  30. 30. 1 require ‘spec_helper‘2 describe AddressController do34 it ‘should calculate shipping‘ do5 get :shipping, :zipcode => ‘90210‘6 assigns(:shipping).should == ‘8.2‘7 end89 end
  31. 31. fixturesconsideredharmful?
  32. 32. <- costumer facing VS backoffice ->
  33. 33. JAVASCRIPT?
  34. 34. module(MultiSelectQuizTests,{ setup: function() { var container = document.getElementById("qunit-fixture"); var question = "Which foods are Mexican?"; var answers = [ { answerText: Tacos, value: true }, { answerText: Sushi, value: false } ]; this.myQuiz = new MultiSelectQuiz ( container, question, answers ); },});test( "One correct", function() { checkRadio(0, true); checkRadio(1, true); deepEqual(this.myQuiz.grade(), 1, "just 1");});
  35. 35. Being goodat stupiddoesn’tcount.
  36. 36. WHY DOWE TEST?
  37. 37. Murphy’s law
  38. 38. PAIN
  39. 39. FLOW
  40. 40. Speed Robustness
  41. 41. How muchQUALITY isENOUGH?
  42. 42. Bugs/1KLOC 5 0,004 4 3 1 0 Indústria Nasa
  43. 43. Cost($/LOC) 850 900 675 450 225 5 0 Indústria Nasa
  44. 44. @marickI test the high risk code thoroughly.I use up most of the remaining timetesting the medium risk code.I don’t intentionally test the low riskcode.
  45. 45. @martinfowleryou’re doing enough testing if thefollowing is true: ■You rarely get bugs that escape into production ■You are rarely hesitant to change some code for fear it will cause production bugs
  46. 46. @jamesshoreSkill and discipline give us fluency.Then fluency gives us ease and joy.
  47. 47. LESSONSLEARNED
  48. 48. baby steps:grow up,the realworld is nota dojo
  49. 49. DRY
  50. 50. WET
  51. 51. Testjourneys
  52. 52. Too muchsleep()
  53. 53. non-deterministicor flaky testsuite
  54. 54. @googleIf they fail we simply run flaky tests3x (and keep statistics). Developertime is much more valuable thanserver time.
  55. 55. @javosantillanI see companies that don’t test realintegration until the very end. Andalso don’t test performance, leaving itto the end, or worse, not testing atall.
  56. 56. externaldependencies:
  57. 57. SCALABILITY SECURITY NON-FUNCTIONAL REQUIREMENTSPERFORMANCE RELIABILITY
  58. 58. technique vs tool
  59. 59. feedback vs noise
  60. 60. Evolutionary design vs Guarantee ofworking software
  61. 61. deciding whatNOT to test isas IMPORTANTas writing tests
  62. 62. bring thepainforward
  63. 63. JOIN the RE- VO- LU- TI-JAVASCRIPT ON
  64. 64. agradecimentos:@camiloribeiro, @lucabastos, @neal4rd,@tottinge, @brownie490, @hugocorbucci,@dtsato, @p_balduino, @mauricioaniche, @cecifernandes, @marick, @mfeathers, @dhh, @martinfowler, @jamesshore, @joshuakeriesvisky, @kentbeck, @unclebobmartin, @klauswuestefeld, @guilhermesilveira, @metayoda, @javosantillan, @rafelmolesin, @davidhussman, @mvaltas

×