testing, testing 1, 2, 3 - dribin.org … · testing, testing... 1, 2, 3 dave dribin – @ddribin...
TRANSCRIPT
![Page 1: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/1.jpg)
Testing, Testing... 1, 2, 3
Dave Dribin
Black Solid
BitMaki Logomarks
1 Color: Deep Green
Design: MakaluMedia www.makalumedia.com • [email protected]
Full Color: Deep Green, Bright Green
Deep Green92 Cyan42 Magenta75 Yellow44 Black
Pantone 3435
#0c3124
Bright Green45 Cyan0 Magenta100 Yellow0 Black
Pantone 376
#8cc919
![Page 2: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/2.jpg)
Testing, Testing... 1, 2, 3
Dave Dribin – @ddribin
Black Solid
BitMaki Logomarks
1 Color: Deep Green
Design: MakaluMedia www.makalumedia.com • [email protected]
Full Color: Deep Green, Bright Green
Deep Green92 Cyan42 Magenta75 Yellow44 Black
Pantone 3435
#0c3124
Bright Green45 Cyan0 Magenta100 Yellow0 Black
Pantone 376
#8cc919
![Page 3: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/3.jpg)
Spreading the Test Infection
“Every programmer knows they should write tests for their code. Few do.”
© 1990 Nintendo
![Page 4: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/4.jpg)
![Page 5: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/5.jpg)
© 2009 Microsoft
![Page 6: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/6.jpg)
Software Testing
• Find bugs
• Meets user expectations
• Provide confidence in software
![Page 7: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/7.jpg)
Categories of Tests
System Tests Unit Tests
Whole
Application
Single Class
Functional Tests
![Page 8: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/8.jpg)
System Tests: Benefits
• Tests the application as it’s shipping
• Often gets customer involved
• Useful for usability and performance testing
![Page 9: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/9.jpg)
System Tests: Disadvantages
• More difficult to automate
• More difficult to test edge cases
• Errors harder to debug
• Slow feedback cycle
![Page 10: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/10.jpg)
What is a Unit Test?
• Tests a single class
• Very fast
• Automated
• Repeatability
• Self-checking
![Page 11: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/11.jpg)
A test is not a unit test if:
• It talks to the database
• It communicates across the network
• It touches the file system
• It can't run at the same time as any of your other unit tests
• You have to do special things to your environment
Michael Feathers, idealized unit test
![Page 12: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/12.jpg)
#import <Foundation/Foundation.h>
@interface Rectangle : NSObject{ float _leftX; float _bottomY; float _width; float _height;}
@property (readonly) float perimeter;@property (readonly) float area;
- (id) initWithLeftX:(float)leftX bottomY:(float)bottomY width:(float)width height:(float)height;
@end
![Page 13: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/13.jpg)
#import <Foundation/Foundation.h>#import <SenTestingKit/SenTestingKit.h>#import "Rectangle.h"
@interface RectangleTest : SenTestCase@end
@implementation RectangleTest
- (void)testPerimeter{ // ...}
- (void)testArea{ // ...}
@end
![Page 14: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/14.jpg)
- (void)testPerimeter{ // Setup Rectangle * rectangle = [[[Rectangle alloc] initWithLeftX:5 bottomY:3 width:8 height:9] autorelease]; // Exercise float actualPerimeter = rectangle.perimeter; // Verify STAssertEqualsWithAccuracy(actualPerimeter, 34.0f, 0.01f, nil);}
![Page 15: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/15.jpg)
Unit Tests: Benefits
• Lots of regression tests catch when changes break existing code
• Allows safe refactoring
• Cleaner, easier to maintain code
• Test hard-to-run conditions (network errors, disk errors, date related)
• Locality of errors
• Tests as sample code
• Faster development
![Page 16: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/16.jpg)
Refactoring
![Page 17: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/17.jpg)
Refactoring
“You keep using that word. I do not think it means what you think it means.”
![Page 18: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/18.jpg)
![Page 19: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/19.jpg)
Refactoring
• Refactoring (noun): a small incremental change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.
![Page 20: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/20.jpg)
Why Refactor
• Improves the design after it has been written
• Makes software easier to understand
• Helps you find bugs
• Helps you program faster
![Page 21: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/21.jpg)
Refactoring
• “It is essential for refactoring that you have good tests.”
• “The tests are essential because even though I follow refactorings [...] I’m still human and still make mistakes.”
• “Refactoring requires tests. If you want to refactor, you have to write tests.”
![Page 22: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/22.jpg)
Writing Tests After Code
• Takes a lot of discipline
• Often skipped due to lack of time
• Hard to retrofit tests on existing code
![Page 23: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/23.jpg)
Writing Tests Before Code
• Write failing tests first
• Implement code so tests pass
• Refactor to make it clean
![Page 24: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/24.jpg)
Test Driven Development
• Make it fail
• Make it work
• Make it clean
• “An acquired taste”
![Page 25: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/25.jpg)
Resistance to Unit Testing
• Writing tests is a bunch of extra code.
• It’ll slow me down
• I’m working with an existing code base, and it’s hard to add tests
• I don’t know how to write unit tests
• TDD sounds ridiculous
![Page 26: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/26.jpg)
Other communities are “Test Infected”
• Java
• JUnit
• Ruby and Ruby on Rails
• New Rails app creates functional, integration, and unit tests directories
![Page 27: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/27.jpg)
![Page 28: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/28.jpg)
Lack of Testing in Objective-C Community
• Why?
• “Mac OS X/iPhone apps are more UI centric”
• Plenty of non-drawing code to test
• Model-View-Controller actually makes code easier to test
• As do delegates
• But... tendency towards large controller classes
![Page 29: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/29.jpg)
![Page 30: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/30.jpg)
![Page 31: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/31.jpg)
![Page 32: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/32.jpg)
![Page 33: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/33.jpg)
![Page 34: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/34.jpg)
![Page 35: Testing, Testing 1, 2, 3 - dribin.org … · Testing, Testing... 1, 2, 3 Dave Dribin – @ddribin Black Solid BitMaki Logomarks 1 Color: Deep Green Design: MakaluMedia • mike@makalumedia.com](https://reader034.vdocuments.mx/reader034/viewer/2022052314/5f0716127e708231d41b3bcf/html5/thumbnails/35.jpg)
http://www.flickr.com/photos/sebastian_bergmann/2282734669/