41
Software OpenTalks :// . . http tabrizsoftware opentalks co @SamadKoushan test-Driven Development test-Driven Development

Tdd - introduction

Embed Size (px)

DESCRIPTION

Introduction to Test Driven Development Software OpenTalks in Tabriz

Citation preview

Page 1: Tdd - introduction

Software OpenTalks:// . .http tabrizsoftware opentalks co@SamadKoushan

test-Driven

Development

test-Driven

Development

Page 2: Tdd - introduction

Programming in Real Programming in Real

DeadLine

Error

ErrorWarning

Notice

Warning

WarningWarningNotice

Notice

Notice

Notice

Page 3: Tdd - introduction

Alpha Version Alpha Version

Alpha Version!!! Who would get off ?

Page 4: Tdd - introduction

Alpha Version Alpha Version

A group of ten top software engineers is sent to a class for aspiring managers. The teacher walks in and asks this question:

"You work for a software company which develops avionics (software that controls the instruments of an airplane). One day you are taking a business trip. As you get on the plane you see a plaque that says this plane is using a beta of the software your team developed. Who would get off?"

Nine developers raised their hands. The teacher looked at the tenth and asked, "Why would you stay on?"

The tenth said, "if my team wrote the software, the plane would not get off the ground, much less crash."

Page 5: Tdd - introduction

Automated Testing Automated Testing

This is programming, you should never just hope that your code works properly, you should be able to prove it and prove it again and again, every step of the way, from the very first lines of code you write, all the way through deploying the application.

Page 6: Tdd - introduction

Automated Testing Automated TestingUncle Bob: The only way to go fast, is to go well.

Page 7: Tdd - introduction

Automated Testing Automated Testing

TDD is not about how to test software!

We are not talking about:

- beta testing- performance testing- stress testing- integration testing- regression testing- usability testing- ...

Page 8: Tdd - introduction

Automated Testing Automated Testing

Unit testing: testing we do as programmers not as end-users. We are testing the code itself. Not just the results we may get from clicking button on a user interface.This is about us, testing the individual units of our code, smallest logical piece as possible.We are proving that single class, works the way that class supposed to.

If we passing these particular values into that particular method, we will get this specific result back, and then we go ahead and prove that this is true.

Page 9: Tdd - introduction

Automated Testing Automated Testing

Automated vs manual testing

Extra Bonus: modifyingHaving automated unit tests allow us to easily validate that any changes we made one place, tomorrow or six month later, doesn't break something that we did earlier.

We will write code that tests our application code, so we have our application code and saved right along side, our simple repeatable testing code.

Page 10: Tdd - introduction

TDDvsUnit Testing TDDvsUnit Testing

It is not Programming unit test

It is Test Driven Development

Unit test: Wrtie code → write test

TDD: Wrtie test → write code

Page 11: Tdd - introduction

QAQA

Does TDD Work for everything? - NO

- multi threading- security options- UI testing- Game development

Best practice : 90% or 80% Code Coverage

Page 12: Tdd - introduction

QAQAAm I supposed to write all my tests first?

9:00:00 AM Write a test9:00:20 AM see test fails9:00:30 AM start writing code to just pass the test

Page 13: Tdd - introduction

QAQAWe have testers, do they write these tests?

You are coding so you have to write unit tests yourself

Page 14: Tdd - introduction

QAQATDD does not fix every issues! -That's right!

-Gives you confidence

-Gives you documentation

-Free you from The Debugger

Page 15: Tdd - introduction

TDDTDD

Page 16: Tdd - introduction

HOWHOWWriting our test class?

Page 17: Tdd - introduction

FrameworkFramework

SUnitSmallTalk

JunitJava

PHPUnitPHP

Nunit.NET

PyUnitPython

CppUnitC++

….ETC

Xunit Frameworks

Page 18: Tdd - introduction

AssertAssertI assert that the earth moves around the sun

- Not asking a question- Not a IF- Not Opinion

- Stating that something be true- Can be positive or negative

- Not replacing exception handler or error messages

- One logical Assertion per test- Each test should have only one reason to fail

Page 19: Tdd - introduction

AssertAssert

Page 20: Tdd - introduction

simpleTestsimpleTestWrite a test

Page 21: Tdd - introduction

simpleTestsimpleTestWrite a test and Watch it fails

Page 22: Tdd - introduction

simpleTestsimpleTestWrite a code and run test again

Page 23: Tdd - introduction

simpleTestsimpleTestrefactor

Page 24: Tdd - introduction

TDDTDD

Page 25: Tdd - introduction

TDDTDD

Page 26: Tdd - introduction

AAAAAA

Page 27: Tdd - introduction

AAAAAA

Page 28: Tdd - introduction

Testing for Expected Exceptions Testing for Expected Exceptions

Page 29: Tdd - introduction

Testing for Expected Exceptions Testing for Expected Exceptions

Page 30: Tdd - introduction

Testing for Expected Exceptions Testing for Expected Exceptions

Page 31: Tdd - introduction

SettingUp and TearingDown SettingUp and TearingDown

Page 32: Tdd - introduction

SettingUp and TearingDown SettingUp and TearingDown

Page 33: Tdd - introduction

SettingUp and TearingDown SettingUp and TearingDown

Page 34: Tdd - introduction

SettingUp and TearingDown SettingUp and TearingDown

Page 35: Tdd - introduction

QAQA

Do I test getters and setters?

Do I test private methods?

Can I combine multiple test classes?Test Suites

How do I control the order of tests?You cannot!

Page 36: Tdd - introduction

MockObjects MockObjects

Page 37: Tdd - introduction

MockObjects MockObjects

Page 38: Tdd - introduction

MockObjects MockObjects

Page 39: Tdd - introduction

MockObjects MockObjects

Page 40: Tdd - introduction

MockObjects And FakeObjects MockObjects And FakeObjects

Page 41: Tdd - introduction

...AndMore ...AndMore

Test-driven Development By ExampleKent BeckAddison Wesley

Refactoring: Improving the Design of Existing CodeMartin Fowler , Kent Beck , ...Addison Wesley

Growing Object-Oriented Software, Guided by TestsSteve FreemanAddison Wesley