AmdJavaMeetupTDDWorkshop

14
TDD Workshop By Gopal Shah

description

Slide used for Ahmedabad Java Meetup on 25th Jan 2014

Transcript of AmdJavaMeetupTDDWorkshop

Page 1: AmdJavaMeetupTDDWorkshop

TDD Workshop

By Gopal Shah

Page 2: AmdJavaMeetupTDDWorkshop

Agenda

● Self Coding session – 45m

● Introduction to TDD – 15m

● TDD Group coding session – Part1 – 45m

● Break – 10m

● TDD Group coding session - Part2 – 45m

● TDD best practices & solution analysis – 30m

● Q & A – 20m

Page 3: AmdJavaMeetupTDDWorkshop

What is the workshop about?

Why TDD?

Should I write unit test for getter/setter?

When should I use mock library?

How do I write tests for static methods?

The problem is complex, where do I start?

I have a tight deadline … can I write tests later?

Is 100% test coverage a myth?

Page 4: AmdJavaMeetupTDDWorkshop

Break for coding session

Page 5: AmdJavaMeetupTDDWorkshop

Agile

● Individuals and interactions over Processes and tools

● Working software over Comprehensive documentation

● Customer collaboration over Contract negotiation

● Responding to change over Following a plan

Page 6: AmdJavaMeetupTDDWorkshop

TDD

Page 7: AmdJavaMeetupTDDWorkshop

Refactoring

● Code refactoring is a "disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior",[1]

● undertaken in order to improve some of the nonfunctional attributes of the software.

● Advantages include improved code readability and reduced complexity to improve the maintainability of the source code,

● as well as a more expressive internal architecture or object model to improve extensibility.

Page 8: AmdJavaMeetupTDDWorkshop

Red bar patterns

● One step test

● Starter test

● Explanation test

● Regression test

● Do over

Page 9: AmdJavaMeetupTDDWorkshop

Green bar patterns

● Isolated tests

● Fake it

● Triangulate

● Obvious implementation

Page 10: AmdJavaMeetupTDDWorkshop

Smells for bad tests

● Long setup code

● Setup duplication

● Long running tests

● Fragile tests

Page 11: AmdJavaMeetupTDDWorkshop

When should you delete tests?

● Confidence

● Communication

Page 12: AmdJavaMeetupTDDWorkshop

What have we learned?

Why TDD?

Should I write unit test for getter/setter?

When should I use mock library?

How do I write tests for static methods?

The problem is complex, where do I start?

I have a tight deadline … can I write tests later?

Is 100% test coverage a myth?

Page 13: AmdJavaMeetupTDDWorkshop

How Does TDD Relate To Patterns?

“Another relationship between TDD and patterns is TDD as an implementation method for pattern-driven design. Say we decide we want a Strategy for something. We write a test for the first variant and implement it as a method. Then we consciously write a test for the second variant, expecting the refactoring phase to drive us to a Strategy. Robert Martin and I did some research into this style of TDD. The problem is the design keeps surprising you. Perfectly sensible design ideas turn out to be wrong. Better to just think about what you want the system to do, and let the design sort itself out later”

- Kent Beck

Page 14: AmdJavaMeetupTDDWorkshop

Few links

● http://martinfowler.com/bliki/ComposedRegex.html

● http://blog.flimflan.com/ReadableRegularExpressions.html

● http://martinfowler.com/articles/mocksArentStubs.html