Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
TDD - Survival Guide
Vitali Perchonok [ vitali.pe@gmail.com ]
A very simple workflow, That focuses on
code correctness, flexibility and clarity.
TDD Is
Here’s The Basic Workflow
Write a test that fails
Start Here
Here’s The Basic Workflow
Write a test that fails Make it pass
Start Here
Here’s The Basic Workflow
Write a test that fails Make it pass
Refactor
Start Here
A replacement for a good high level design.
TDD Is NOT
TDD is bottom-up by nature which makes it hard to see the big pictu...
The same as unit testing
TDD Is NOT
TDD is a workflow, You use unit tests as a tool to drive your design
and ensure that y...
A replacement for your QA
TDD Is NOT
Unit tests are simply not enough, There are also Usability Tests
Integration tests, P...
The 3 Rules Of TDD
1. You are not allowed to write any production code unless
it is to make a failing unit test pass.
The 3 Rules Of TDD
1. You are not allowed to write any production code unless
it is to make a failing unit test pass.
2. Y...
The 3 Rules Of TDD
1. You are not allowed to write any production code unless
it is to make a failing unit test pass.
2. Y...
Wait, What’s a Unit Test?
Code that tests certain behavior in an isolated component.
def test_covert_red_from_RGB_to_HSL(s...
Remember, It’s NOT A Unit Test If
● It touches the file system or the DB (read || write)
● It communicates across the netw...
Anatomy Of A Unit Test
class TestAssetLoader(unittest.TestCase):
...
def test_should_only_load_assets_once(self):
fakeFile...
Anatomy Of A Unit Test
fakeFileReader = FakeFileReader()
assetManager = AssetManager(fakeFileReader)
assetManager.getImage...
Fakes (Mocks, Stubs, Spies)
Fakes Are Basically Used To:
1. Isolate the component under test from the rest of the system.
...
Fakes (Mocks, Stubs, Spies)
● Stub is just a dummy object to fill the role of a real object.
● Mock is a stub with an asse...
QA
Code
Próxima SlideShare
Cargando en…5
×

TDD - survival guide

515 visualizaciones

Publicado el

Publicado en: Software, Tecnología, Educación
  • Finally found a service provider which actually supplies an essay with an engaging introduction leading to the main body of the exposition Here is the site ⇒⇒⇒WRITE-MY-PAPER.net ⇐⇐⇐
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/xS3Nn ◀ ◀ ◀ ◀
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/xS3Nn ◀ ◀ ◀ ◀
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • Sé el primero en recomendar esto

TDD - survival guide

  1. 1. TDD - Survival Guide Vitali Perchonok [ vitali.pe@gmail.com ]
  2. 2. A very simple workflow, That focuses on code correctness, flexibility and clarity. TDD Is
  3. 3. Here’s The Basic Workflow Write a test that fails Start Here
  4. 4. Here’s The Basic Workflow Write a test that fails Make it pass Start Here
  5. 5. Here’s The Basic Workflow Write a test that fails Make it pass Refactor Start Here
  6. 6. A replacement for a good high level design. TDD Is NOT TDD is bottom-up by nature which makes it hard to see the big picture. NOTE: Many people will disagree with me on this one! Also sometimes by starting with a high level architecture I can leverage existing knowledge, this is why frameworks like QT exist.
  7. 7. The same as unit testing TDD Is NOT TDD is a workflow, You use unit tests as a tool to drive your design and ensure that you’re on the right track. Unit tests can be (and are) used outside the scope of TDD. It is true however that writing good unit tests on existing code is very hard.
  8. 8. A replacement for your QA TDD Is NOT Unit tests are simply not enough, There are also Usability Tests Integration tests, Performance tests etc…
  9. 9. The 3 Rules Of TDD 1. You are not allowed to write any production code unless it is to make a failing unit test pass.
  10. 10. The 3 Rules Of TDD 1. You are not allowed to write any production code unless it is to make a failing unit test pass. 2. You are not allowed to write any more of a unit test than is sufficient to fail.
  11. 11. The 3 Rules Of TDD 1. You are not allowed to write any production code unless it is to make a failing unit test pass. 2. You are not allowed to write any more of a unit test than is sufficient to fail. 3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
  12. 12. Wait, What’s a Unit Test? Code that tests certain behavior in an isolated component. def test_covert_red_from_RGB_to_HSL(self): redHSL = [0, 100, 50] self.assertListEqual(redHSL, rgb2hsl(255,0, 0)) def test_start_car_with_no_gas_should_throw_error(self): emptyGasTank = FakeGasTank() car = Car(emptyGasTank, FakeEngine()) emptyGasTank.gasLeft = MagicMock(return_value=0) # new in python 3.3 self.assertRaises(CustomError, car.start)
  13. 13. Remember, It’s NOT A Unit Test If ● It touches the file system or the DB (read || write) ● It communicates across the network ● It can’t run in parallel with other unit tests. ● It contains randomness, (i.e different each time you run it). ● It requires you to modify the environment (edit config etc…) ● It doesn't contain an assert statement.
  14. 14. Anatomy Of A Unit Test class TestAssetLoader(unittest.TestCase): ... def test_should_only_load_assets_once(self): fakeFileReader = FakeFileReader() assetManager = AssetManager(fakeFileReader) assetManager.getImage("kozet_the_sheep") assetManager.getImage("kozet_the_sheep") self.assertEqual(1, fakeFileReader.load.call_count) ...
  15. 15. Anatomy Of A Unit Test fakeFileReader = FakeFileReader() assetManager = AssetManager(fakeFileReader) assetManager.getImage("kozet_the_sheep") assetManager.getImage("kozet_the_sheep") self.assertEqual(1, fakeFileReader.load.call_count) Arrange Act Assert Arrange Act Assert (AAA) Pattern
  16. 16. Fakes (Mocks, Stubs, Spies) Fakes Are Basically Used To: 1. Isolate the component under test from the rest of the system. 2. Inspect the effects on the outside world.
  17. 17. Fakes (Mocks, Stubs, Spies) ● Stub is just a dummy object to fill the role of a real object. ● Mock is a stub with an assert condition inside. ● Spy is just a wrapper that stores info like number of calls, parameters etc... Here’s a simple way to think about them: Most of the time when people say mock they actually mean stub. But it’s not important as long as you don’t use no more than 1 real mock in a test.
  18. 18. QA
  19. 19. Code

×