what not to test in your project

79
What NOT to test in your project

Upload: alexandre-freire

Post on 29-Jun-2015

863 views

Category:

Documents


2 download

DESCRIPTION

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...

TRANSCRIPT

Page 1: What NOT to test in your project

What NOT to test in your project

Page 2: What NOT to test in your project
Page 3: What NOT to test in your project

?

Page 4: What NOT to test in your project
Page 5: What NOT to test in your project

1describe “test” do2 it “should do nothing” do3 fail4 end5 end

Page 6: What NOT to test in your project
Page 7: What NOT to test in your project

1describe “test” do2 it “should do nothing” do3 fail4 end5 end

Page 8: What NOT to test in your project

1describe “test” do2 it “should do nothing” do3 true4 end5 end

Page 9: What NOT to test in your project
Page 10: What NOT to test in your project

1describe “test” do2 it “should do nothing” do3 true4 end5 end ?

Page 11: What NOT to test in your project

Do you DELETE your tests?

Page 12: What NOT to test in your project

@davidhussmanI think that tests that never fail should be deleted. If a test doesn’t communicate something meaningful about the desing, what is it’s value?

Page 13: What NOT to test in your project

@dhhI find over-testing to be most common among those 1st adopting TDD. So excited about the idea that they go completely overboard.

Page 14: What NOT to test in your project

Don’t use Cucumber unless you live in the magic kingdom of non-coders-writing-tests (and send me some fairy dust if you are!)

Page 15: What NOT to test in your project

@mfeathers Ultimately, tests are a feedback mechanism, and we should make active decisions about what feedback we need and when.

Page 16: What NOT to test in your project
Page 17: What NOT to test in your project
Page 18: What NOT to test in your project

@unclebobmartin 1 of Kent’s older wise sayings was: “Test everything that could possibly break.” I think that’s a pretty good recipe.

Page 19: What NOT to test in your project
Page 20: What NOT to test in your project

@metayodaI would rather have 10% coverage with 100% quality tests, than 100% coverage with lousy tests.

Page 21: What NOT to test in your project
Page 22: What NOT to test in your project

@joshuakerievskyTest first/after misses the point that TDD is more about emergent design than it is about testing. Do you practice emergent design?

Page 23: What NOT to test in your project

@kentbeckIf I don’t typically make a mistake(...), I don’t test for it.

Wish there were more examples of “what not to test”.

Page 24: What NOT to test in your project
Page 25: What NOT to test in your project

60@Test61public void setPrice() {62 Item item = new 63 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}

Page 26: What NOT to test in your project

74@Test75public void isImported_true(){76 Item item = new 77 BasicItem(0.0, true);78 79 assertTrue(item.isImported());80}

Page 27: What NOT to test in your project

74@Test75public void isImported_false(){76 Item item = new 77 BasicItem(0.0, false);78 79 assertFalse(item.isImported());80}

Page 28: What NOT to test in your project

28public Double getPrice(){ 25 return price;26} 2728public boolean isImported(){29 return imported;30}

Page 29: What NOT to test in your project

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

Page 30: What NOT to test in your project

1 require ‘spec_helper‘2 describe Candidate do 3 context ‘associations‘ do4 it { should have_many(:proposals) }5 end6 7 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 } 14 15 it { should_not16 allow_value(‘blah‘).for(:site) }1718 it { should19 allow_value(‘http://www.blah.com‘)20 .for(:site) }21 end22end

Page 31: What NOT to test in your project

1 require ‘valid_url‘2 class Candidate < ActiveRecord::Base 3 has_many :proposals45 validates :name, presence: true67 validates :phone, :length =>8 {:in => 8..14},9 :allow_blank10 11 validates :site, :url => true,12 :allow_nil => true13 14end

Page 32: What NOT to test in your project

1 require ‘spec_helper‘2 describe Candidates do 3 4 let(:candidate) {double ‘candidate‘}5 6 before :each do7 Candidate8 .should_receive(:find)9 .with(1).and_return(candidate)10 end11 12 it ‘should find the candidate‘ do13 c = Candidate.find(1)14 c.should eql candidate15 end16end

Page 33: What NOT to test in your project

1Feature: Create proposal 2 As a candidate 3 I want to post my proposals 4 So that voters can evaluate them 5 6 Scenario: 7 Given I am logged in 8 And I am posting a proposal9 When 10 I fill all fields of the proposal11 Then 12 I should see a success message

Page 34: What NOT to test in your project

1Scenario: Client sees tooltip for plan 2 Given 3 I select the ‘light‘ plan 4 When 5 I mouse over ‘tooltip‘6 Then 7 I should see ‘tooltip‘ content8 And 9 I mouse out ‘tooltip‘10 Then 11 I should not see ‘tooltip‘ content

Page 35: What NOT to test in your project

1require ‘spec_helper‘2describe ShoppingCart do 3 4 let(:user) {double ‘user‘}5 let(:product) {double ‘product‘}6 7 before :each do8 Authenticator.should_receive(:auth)9 .and_return(true)10 end11 12 it ‘should addProduct & getTotal‘ do13 Authenticator.auth(user)14 cart = ShoppingCart.new15 cart.add_product(product)16 cart.get_total17 end18end

Page 36: What NOT to test in your project

100% COVERED CODE.

OF CODE YOU COVERLINE

Page 37: What NOT to test in your project

PIXEL NAZI

Page 38: What NOT to test in your project

50@Test51public void changeMarks() {52 bot.leftClickAt(view,53 800, 508);54 addMarkAt(‘drama’, 1);55 56 bot.leftClickAt(view,57 900, 508);58 addMarkAt(‘act’, 3);5960 bot.verifyTooltipAt(30, 190);61}

Page 39: What NOT to test in your project

1 require ‘spec_helper‘2 describe AddressController do 3 4 it ‘should calculate shipping‘ do5 get :shipping, :zipcode => ‘90210‘6 assigns(:shipping).should == ‘8.2‘7 end89 end

Page 40: What NOT to test in your project
Page 41: What NOT to test in your project

fixtures considered harmful?

Page 42: What NOT to test in your project

VS

<- costumerfacing

back office ->

Page 43: What NOT to test in your project

JAVASCRIPT?

Page 44: What NOT to test in your project

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");});

Page 45: What NOT to test in your project

Being good at stupid doesn’t count.

Page 46: What NOT to test in your project

WHY DO WE TEST?

Page 47: What NOT to test in your project

Murphy’s law

Page 48: What NOT to test in your project

PAIN

Page 49: What NOT to test in your project
Page 50: What NOT to test in your project

FLOW

Page 51: What NOT to test in your project

Speed Robustness

Page 52: What NOT to test in your project
Page 53: What NOT to test in your project

How much QUALITY is ENOUGH?

Page 54: What NOT to test in your project

Bugs/1KLOC

0

1

3

4

5

Indústria Nasa

0,004

Page 55: What NOT to test in your project

Cost($/LOC)

0

225

450

675

900

Indústria Nasa

5

850

Page 56: What NOT to test in your project

@marickI test the high risk code thoroughly. I use up most of the remaining time testing the medium risk code.I don’t intentionally test the low risk code.

Page 57: What NOT to test in your project

@martinfowleryou’re doing enough testing if the following 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

Page 58: What NOT to test in your project

@jamesshoreSkill and discipline give us fluency. Then fluency gives us ease and joy.

Page 59: What NOT to test in your project
Page 60: What NOT to test in your project

LESSONS LEARNED

Page 61: What NOT to test in your project

baby steps: grow up, the real world is not a dojo

Page 62: What NOT to test in your project

DRY

Page 63: What NOT to test in your project

WET

Page 64: What NOT to test in your project

Test journeys

Page 65: What NOT to test in your project

Too muchsleep()

Page 66: What NOT to test in your project

non-deterministic or flaky test suite

Page 67: What NOT to test in your project
Page 68: What NOT to test in your project

@googleIf they fail we simply run flaky tests 3x (and keep statistics). Developer time is much more valuable than server time.

Page 69: What NOT to test in your project

@javosantillanI see companies that don’t test real integration until the very end. And also don’t test performance, leaving it to the end, or worse, not testing at all.

Page 70: What NOT to test in your project

external dependencies:

Page 71: What NOT to test in your project

NON-FUNCTIONAL REQUIREMENTS

SCALABILITY

RELIABILITY

SECURITY

PERFORMANCE

Page 72: What NOT to test in your project
Page 73: What NOT to test in your project

techniquevs

tool

Page 74: What NOT to test in your project

feedbackvs

noise

Page 75: What NOT to test in your project

Evolutionary design

vsGuarantee of

working software

Page 76: What NOT to test in your project

deciding what NOT to test is as IMPORTANT as writing tests

Page 77: What NOT to test in your project

bring the pain forward

Page 78: What NOT to test in your project

JAVASCRIPT

JOINtheRE-VO-LU-TI-ON

Page 79: What NOT to test in your project

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