TDD Unit tests from a slightly different point of view Katie Dwyer.

Slides:



Advertisements
Similar presentations
Test-First Programming. The tests should drive you to write the code, the reason you write code is to get a test to succeed, and you should only write.
Advertisements

A practical guide John E. Boal TestDrivenDeveloper.com.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
A Brief Introduction to Test- Driven Development Shawn M. Jones.
Testing and Debugging CS221 – 2/13/09. Airline Program.
Test-Driven Development “Test first, develop later!” –OCUnit.
Test Driven Development Derived from Dr. Fawcett’s notes Phil Pratt-Szeliga Fall 2009.
Test-Driven Development Gary Brown Building better software one test at a time.
LESSONS Learn & Live Your Life!!!. When you lose someone, your heart breaks wide open, and the bad news is you never completely get over the loss. You.
By for Test Driven Development: Industry practice and teaching tool Robert Vanderwall, Ph.D. 1 WISTPC-15.
Test-Driven Development With Visual Studio 2005 Erno de Weerd Info Support.
TDD,BDD and Unit Testing in Ruby
Test Driven Development TDD. Testing ”Testing can never demonstrate the absence of errors in software, only their presence” Edsger W. Dijkstra (but it.
Test Driven Development An approach to writing better code Jimmy Zimmerman Intel Corporation.
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
@benday #vslive Automated Build, Test & Deploy with TFS, ASP.NET, and SQL Server Benjamin
15 Improve Your Life!!! Tips. Be honest about what you want to achieve and who you want to become. Be honest with every aspect of your life, always. Because.
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
By for Testing Tools: Test Automation and supporting tools Jariro Pava, Robert Vanderwall 1 WISTPC-14.
Sofia Bulgaria Summer School IST eXPERT: Best Practice on e-Project Development 30 June - 2 July 2003 eXtreme programming.
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
TEST-1 6. Testing & Refactoring. TEST-2 How we create classes? We think about what a class must do We focus on its implementation We write fields We write.
Spring Conferences th Grade : Ms. Blacker Student Name.
1 Legacy Code From Feathers, Ch 2 Steve Chenoweth, RHIT Right – Your basic Legacy, from Subaru, starting at $ 20,295, 24 city, 32 highway.
Test-Driven Development Eduard Miric ă. The problem.
1 Presentation Title Test-driven development (TDD) Overview David Wu.
Henrik Bærbak Christensen1 Test Driven Development “TDD” Summary.
(1) Test Driven Development Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Version Control and SVN ECE 297. Why Do We Need Version Control?
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
Continuous Improvement. Start Simple and Continually Improve E.g., Gmail Labels 1.
Software Development. The Software Life Cycle Encompasses all activities from initial analysis until obsolescence Analysis of problem or request Analysis.
Code Simplicity: Software Design In Open Source Projects Max Kanat-Alexander
JavaScript: API’s, Parameters and Creating Functions with Parameters
Software Development.
AP CSP: Cleaning Data & Creating Summary Tables
Section title This presentation is designed to help you talk to young people about Drive. The notes included aren’t intended to be read out, they are for.
Developer Testing Tricks
Steve Chenoweth Office Phone: (812) Cell: (937)
C++ coding standard suggestion… Separate reasoning from action, in every block. Hi, this talk is to suggest a rule (or guideline) to simplify C++ code.
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
Paul Ammann & Jeff Offutt
In the message bar, click Enable Editing,
TDD Overview CS 4501/6501 Software Testing
Client Management Managing Client Expectations
Unit Testing in a Team Sparkhound Presents by Steve Schaneville
I’m going to talk about my vision for the future of system administration, and a question for you to contemplate.
Pseudo-ops, Debugging, etc.
Refactoring and Code Smells
Johanna Rothman Create Technical Excellence Chapter 9
Paul Ammann & Jeff Offutt
Get Good at DevOps: Feature Flag Deployments with ASP
Words and Actions Can Hurt
Test-driven development (TDD)
Refactoring Legacy AngularJS
Introducing the Ideas One of Six Traits:
Refactoring and Code Smells
CSCE 489- Problem Solving Programming Strategies Spring 2018
CS240: Advanced Programming Concepts
CSE 303 Concepts and Tools for Software Development
Dr. Rob Hasker SE 3800 Note 9 Reviews.
Refactoring.
Tonga Institute of Higher Education IT 141: Information Systems
Data journalism projects
Tonga Institute of Higher Education IT 141: Information Systems
Refactoring Low Level/High Level.
"Anything worth doing, is worth doing right." Hunter S. Thompson
Software Development Techniques
THANK YOU, SPONSORS! Rockstar Sponsors!.
Refactoring and Code Smells
Presentation transcript:

TDD Unit tests from a slightly different point of view Katie Dwyer

About me... ● My favorite topic ● Bachelors and Masters degree in CS from NKU ● Occasionally teach Intro to OOP at NKU ● Yeah, not a big fan of change ● Got into Agile in October 2010 ● CSM, CSD, working on PMI-ACP ● Consultant for Sogeti, working as Release Manager for SAP Mobile at Cintas ● On Sogeti's Agility Council

On the Agenda ● Wait, what are you talking about? ● Developers either love TDD or hate it, why? ● Why bother? ● How do I start? ● You're only as good as your tests ● Tips

Wait, what are you talking about?

What in the world is TDD? ● Test-Driven Development ● Testing Drives Development (duh) ● Not a testing technique! ● Programming technique associated with Agile/XP

That didn't answer my question For every code change: 1. Write a unit test that fails 2. Change the code just enough that your test passes 3. Verify that rest of the tests pass Refactor if needed and make sure all the tests still pass

Goals of TDD ● Clean code that works ● Simplicity – maximize the work not done ● KISS – Keep It Simple Stupid

So, what's the difference between TDD and Unit Tests? ● You can have unit tests without doing TDD ● You can't do TDD without unit tests ● With TDD, you should have unit tests for all your code.

In TDD, unit tests are tools for development, not afterthoughts.

So TDD gives you the benefits of Unit Testing too ● Prove code works ● Changes don't break other code ● Testable code is well-designed code ● “Cover and modify instead of edit and pray” - Michael Feathers

Developers either love TDD or hate it, why?

Because they hate unit tests.

Different Mindset ● Live for today without planning for the future ● Maximizing the work not done ● A lesson from my daughter

Thanks, Ally

Challenges ● Takes longer, especially at first ● Misunderstandings – doesn't replace QA or User Acceptance testing, not a silver bullet ● Code coverage, do I really have to write a unit test for everything? ● Some languages are harder than others, but that means some are easier! ● Sometimes it's harder to write the test than it would be to just make the code change

Really, a second slide of challenges?!? ● Legacy code ● Yes, it gets its own slide

And Another on Legacy Code ● Can be daunting and intimidating ● Design may not be unit test friendly ● Changes are often to existing code rather than new classes/methods ● Anything that needs to be modified should be refactored to add unit tests ● Far slower than TDD with new code

Why Bother? ● Disciplined – focus on quality ● Demonstrate progress ● Lots of refactoring leads to better design ● You can refactor with higher confidence because you have unit tests ● You should have a high percentage of unit test coverage

Oh yes I did drag this out to two slides ● KISS again...less code means less complexity and less bugs ● Bugs are found earlier when they are less expensive to fix ● Nobody breaks your stuff without you knowing

OK, you've convinced me... How do I start?

Unit Test Library ● Select an appropriate unit test library for the language you are using ● Familiarize yourself with the unit test library ● If you are doing TDD with legacy code, code yourself up a toy application using TDD for practice

A journey of a thousand miles begins with a single step, and an application of a thousand lines should begin with a single test.

So just do it already ● Writing the test is often the hard part ● Every logic piece should have a unit test ● You must write a unit test before every code change

Testing Drives the Development ● Write a test for the change you need to make that you expect to fail ● Verify it fails (don't laugh, it happens) – It's okay if doesn't even compile ● Make the code change to make the test pass ● Verify the rest of the tests pass ● Look around and see if you should refactor ● Make sure all the tests still pass after you refactor

You're only as good as your tests...

Each unit test should ● Test one logical piece ● Document correct behavior ● Run fast ● Localize problems

Characteristics of Good Unit Test ● A single unit test should not verify too much functionality ● Unit tests should be independent from each other ● Unit tests shouldn't be heavily dependent on interface

Structure ● Setup ● Invoke what you are testing ● Verify your results ● Clean up

What should “a unit test” test? ● Good data => Good output ● Bad data => Expected output ● Boundary conditions ● Nulls ● Branches

Unit Test Tips ● Use dummy/mock objects ● Minimize assumptions ● Don't hard-code values ● Starting is the hardest part. ● Don't get discouraged!

Mock Objects ● Mimic complex object ● Stand in for real objects ● Same interface as real object ● Simple example: – Test client side logic – A large complex method has a piece that checks permission by hitting the server – Mock out the piece that checks permission and return what you need

Legacy Code Tips ● Add unit tests to document expected behavior as you go ● You can add the unit test and see why it fails and then modify the unit test to pass ● Add unit testing as you go to anything you modify ● Don't try to go back and add unit tests all at once

Refactoring Tips ● Use a tool with support! ● Goals – Reduce dependencies – Introduce seams ● Extract small pieces you understand first ● Divide into logical pieces ● Look for code smells

Code Smells ● Duplicated Code ● Long methods ● God object ● Feature envy ● Inappropriate Intimacy ● Lazy ● Contrived Complexity ● Long identifiers

Q & A

Thank you!!!