What NOT to test in your project
-
Upload
alexandre-freire -
Category
Documents
-
view
861 -
download
2
description
Transcript of What NOT to test in your project
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 you DELETE your tests?
@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?
@dhhI find over-testing to be most common among those 1st adopting TDD. So excited about the idea that they go completely overboard.
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!)
@mfeathers Ultimately, tests are a feedback mechanism, and we should make active decisions about what feedback we need and when.
@unclebobmartin 1 of Kent’s older wise sayings was: “Test everything that could possibly break.” I think that’s a pretty good recipe.
@metayodaI would rather have 10% coverage with 100% quality tests, than 100% coverage with lousy tests.
@joshuakerievskyTest first/after misses the point that TDD is more about emergent design than it is about testing. Do you practice emergent design?
@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 = 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}
74@Test75public void isImported_true(){76 Item item = new 77 BasicItem(0.0, true);78 79 assertTrue(item.isImported());80}
74@Test75public void isImported_false(){76 Item item = new 77 BasicItem(0.0, false);78 79 assertFalse(item.isImported());80}
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 String8 raise “lname must be9 a String”10 unless lname.kind_of?11 String11 end
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
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
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
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
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
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
100% COVERED CODE.
OF CODE YOU COVERLINE
PIXEL NAZI
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}
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
fixtures considered harmful?
VS
<- costumerfacing
back office ->
JAVASCRIPT?
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");});
Being good at stupid doesn’t count.
WHY DO WE TEST?
Murphy’s law
PAIN
FLOW
Speed Robustness
How much QUALITY is ENOUGH?
Bugs/1KLOC
0
1
3
4
5
Indústria Nasa
0,004
Cost($/LOC)
0
225
450
675
900
Indústria Nasa
5
850
@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.
@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
@jamesshoreSkill and discipline give us fluency. Then fluency gives us ease and joy.
LESSONS LEARNED
baby steps: grow up, the real world is not a dojo
DRY
WET
Test journeys
Too muchsleep()
non-deterministic or flaky test suite
@googleIf they fail we simply run flaky tests 3x (and keep statistics). Developer time is much more valuable than server time.
@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.
external dependencies:
NON-FUNCTIONAL REQUIREMENTS
SCALABILITY
RELIABILITY
SECURITY
PERFORMANCE
techniquevs
tool
feedbackvs
noise
Evolutionary design
vsGuarantee of
working software
deciding what NOT to test is as IMPORTANT as writing tests
bring the pain forward
JAVASCRIPT
JOINtheRE-VO-LU-TI-ON
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