Top Banner
@ gil_zilber feld SELA DEVELOPER PRACTICE May 5-9, 2013 Gil Zilberfeld 7 Steps for writing your first test
13

7 Steps for writing your first test

May 11, 2015

Download

Technology

Gil Zilberfeld

Breaking down the unit test writing process into tiny bits. What to think about, what to focus on, and how are tools affect what we do.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 7 Steps for writing your first test

@gil_zilberfeld

SELA DEVELOPER PRACTICEMay 5-9, 2013

Gil Zilberfeld

7 Steps for writing your first test

Page 2: 7 Steps for writing your first test

@gil_zilberfeld

Who am I?

www.typemock.com

typemock.com/blog

@typemock

www.gilzilberfeld.com

[email protected]

@gil_zilberfeld

Page 3: 7 Steps for writing your first test

@gil_zilberfeld

Step 0: Prepare

• Know your tools

• Evaluate the risk

• Choose your partner

Page 4: 7 Steps for writing your first test

@gil_zilberfeld

Step 1: What to test

• What you’re working on• Bug or feature?• Logic• Read it first• What not to test:• Multithreading• Stored procedures• UI

Page 5: 7 Steps for writing your first test

@gil_zilberfeld

Step 2: Get ready

• Pick organization strategy• Create test projects• Remove fluff• VS I’m looking at you

Page 6: 7 Steps for writing your first test

@gil_zilberfeld

Step 3: Pick a scenario

• Scenario consists of • Context• Logic• Success criteria

• Pick the simplest scenario• Say it!• Name it!• Assert it!

:// . . /http erpstore codeplex com

Page 7: 7 Steps for writing your first test

@gil_zilberfeld

Step 4: Identify dependencies• Read the code• Constructor parameters• Fields• Statics• Global state

• Mocking strategy• None• Where to mock• How to mock

Page 8: 7 Steps for writing your first test

@gil_zilberfeld

Step 5: Simplify design

• Refactor with tools: VS, R#, DevExpress• Close down regions you’re not going to cover• Rename fields• Extract methods

• Manual refactoring works too• …but more risky

Page 9: 7 Steps for writing your first test

@gil_zilberfeld

Step 6: Here we go!

• Arrange• Run• Fail• Arrange more• Run• …..• Success!

Page 10: 7 Steps for writing your first test

@gil_zilberfeld

Step 7: Move on!

• Pick the next scenario• Say it• Name it• Assert it

• Mutate the test setup• Arrange• Run • …• Win!

Page 11: 7 Steps for writing your first test

@gil_zilberfeld

Congratulations!

• This is just the beginning• Lifetime improvement• Picking scenarios• Naming• Mocking• Refactoring

Page 12: 7 Steps for writing your first test

@gil_zilberfeld

Would you like to know more?

www.typemock.com

typemock.com/blog

@typemock

www.gilzilberfeld.com

[email protected]

@gil_zilberfeld

Page 13: 7 Steps for writing your first test

@gil_zilberfeld

Thank You