+ All Categories
Home > Technology > TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

Date post: 05-Dec-2014
Category:
Upload: jay-aho
View: 2,383 times
Download: 0 times
Share this document with a friend
Description:
If you've heard of Test-driven Development, and you're wondering what all the fuss is about, this slidedeck will provide a code-centric introduction to the concepts, tools, and practices of TDD in the .NET framework. We'll start with the basics of setting up a unit testing framework and writing the first test, then we'll move on to techniques for mocking dependencies and demonstrate patterns like Dependency Injection that will help you move past testing just the basics. We invite you to download the full webinar replay at http://pillartechnology.com/content/webinardetail/id/15 which includes live demonstrations. After viewing the webinar replay, you should be able to sit down and start writing tests that will drive the design of your application, creating loosely-coupled and testable code.
20
TDD 0 to 60 An Introduction in Test-Driven Development in .NET Michael Joseph Kramer Pillar Technology http://www.flickr.com/photos/purplepick/2554134479/
Transcript
Page 1: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

TDD 0 to 60 An Introduction in

Test-Driven Developmentin .NETMichael Joseph Kramer

Pillar Technology

http://www.flickr.com/photos/purplepick/2554134479/

Page 2: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

What do you mean by “unit test”?

• code tests code

• small

• fast

• independent

http://www.flickr.com/photos/ugocei/6420197/

Page 3: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

the whole truthiness

• Anything I can do with a unit test, I can do with a debugger.• It’s an ivory tower activity, not something real businesses do.• Unit testing isn’t for small businesses.• Unit testing isn’t for the enterprise.• We don’t need no stinkin’ unit tests. We have a QA team!• We don’t need no stinkin’ QA team. We have unit tests!• Writing tests will take me longer, which makes it cost more.• Most of the stuff I write isn’t interesting enough for a unit

tests. It’s only for complicated stuff.• Unit testing prevents you from writing crappy software.• Everything I have ever learned about software development is

wrong.

http://www.flickr.com/photos/thelastminute/142252337/

Page 4: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

What do I need?

• NUnit

• MbUnit

• MsTest

• xUnit.net

http://www.flickr.com/photos/17258892@N05/2588347668/

Page 5: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

http://www.flickr.com/photos/lynac/321100379/

Page 6: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

AAA ain’t just the auto club

Arrange – Set it up!Act – Call It!Assert – Verify it worked!

Page 7: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

http://www.flickr.com/photos/ethomsen/2815081394//

Page 8: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

Is this TDD???

Page 9: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

http://www.flickr.com/photos/37612915@N00/350716275/

Page 10: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

only refactor green tests!

http://www.flickr.com/photos/jshultz/118841012/

Page 11: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

http://http://www.flickr.com/photos/roadsidepictures/469271408//

Page 12: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

Weak. My code uses a database...

http://www.flickr.com/photos/helios89/1373343153

Page 13: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

Dependencies

• inject the dependency

• replace with a stub

http://www.flickr.com/photos/leecullivan/141114012/

Page 14: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

http://www.flickr.com/photos/victius/4064996780/

Page 15: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

Why can’t I just go

to the database?

http://www.flickr.com/photos/richpix/1386265680/

Page 16: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

Mocking: not just for when your manager out of the room

• a mock knows if your test passed

• behavior, not state

• void methods

• brittle

http://www.flickr.com/photos/mariaclarah/927759528/

Page 17: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

http://www.flickr.com/photos/8829172@N02/4010684609/

Page 18: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

Mocks aren’t Stubs, abridged

• Stubs vs. Mocks, in a nutshell:

– Stubs: return dummy data

– Mocks: Test passes or fails based on what the method does, not what it returns

– Test Double or Fake: Generic terms for either a mock or stub

I.E., a mock can make a test fail, a stub can’t.

Full Version: http://martinfowler.com/articles/mocksArentStubs.html

Page 19: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

http://www.flickr.com/photos/marcobellucci/3534516458/

Page 20: TDD 0 to 60 - An Introduction to Test-Driven Development in .NET

• Upcoming Webinars: Please visit pillartechnology.com/events

• All of the webinar content is available to your business in a 1-2 day on-site workshop or as a “lunch and learn” format. Please contact us for details.

• Visit www.pillartechnology.com/events to access presentation slides and full archived broadcasts of past webinars.

• Twitter.com/agilesoftware

• Blog: www.pillartechnology.com/blog

• LinkedIn: Join the Agile Enthusiast Group on LinkedIn: http://bit.ly/agilegroup

• YouTube: http://www.youtube.com/user/PillarTechnology

• Phone: (888) 3-pillar

• Web: pillartechnology.com

• Email: [email protected]

Our Next Steps


Recommended