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.
Retro Testing

Allon Mureinik
Team Lead, Cloud Storage, Red Hat
amureini@redhat.com / @mureinik
January 2014

Allon Murein...
TDD Is Easy...

Allon Mureinik - Retro Testing

2
... or is it?
●

The first two part should be
●

Write a test

●

Make sure it fails

●

The question is why it fails.

●
...
Will the mistakes of the past haunt me
forever?

Allon Mureinik - Retro Testing

4
It’s not an all-or-nothing situation

Allon Mureinik - Retro Testing

5
One baby step at a time

Allon Mureinik - Retro Testing

6
Refactor, refactor, refactor
●

●

Your first task would probably be to do some
refactoring
Resist the urge to improve the...
Refacroting with no tests is like...

Allon Mureinik - Retro Testing

8
Example : Bad Code

Allon Mureinik - Retro Testing

9
Some minimal refactoring

Allon Mureinik - Retro Testing

10
Now we can start writing tests...
●

●

Now we have the tools to separate external resources
from logic
There are a couple...
I @Spy With My Little Eye

Allon Mureinik - Retro Testing

12
Some more refactoring

Allon Mureinik - Retro Testing

13
Let’s modernize our code

Allon Mureinik - Retro Testing

14
But how can I write asserts?
●

Overriding, mocking and all that jazz are fine and well

●

But any test boils down to wri...
Allon Mureinik - Retro Testing

16
The real challenge is changing mindset
●

We can discusses refactoring till we’re blue in the face

●

But the real challe...
It’s all too easy to slip back to bad habits
●

This bug is blocking the release...

●

It’s a ton of work to refactor thi...
Have the courage to stand up to excuses

Allon Mureinik - Retro Testing

19
Questions?

Allon Mureinik - Retro Testing

20
Próxima SlideShare
Cargando en…5
×

Retro Testing (DevConTLV Jan 2014)

826 visualizaciones

Publicado el

Unit testing is easy... In a perfect world.
Our world is not.
This talk will cover a bunch of tips, tricks, and techniques to retrofit ugly legacy applications so parts of them can be unit tested.

(Examples given in Java using JUnit and Mockito)

Publicado en: Tecnología, Educación
  • Inicia sesión para ver los comentarios

  • Sé el primero en recomendar esto

Retro Testing (DevConTLV Jan 2014)

  1. 1. Retro Testing Allon Mureinik Team Lead, Cloud Storage, Red Hat amureini@redhat.com / @mureinik January 2014 Allon Mureinik - Retro Testing 1
  2. 2. TDD Is Easy... Allon Mureinik - Retro Testing 2
  3. 3. ... or is it? ● The first two part should be ● Write a test ● Make sure it fails ● The question is why it fails. ● In a legacy system, it will often fail for “bad” reasons: ● Unable to access the database ● Some static resource not set up ● Need to spin up an application server ● Etc., etc., etc... Allon Mureinik - Retro Testing 3
  4. 4. Will the mistakes of the past haunt me forever? Allon Mureinik - Retro Testing 4
  5. 5. It’s not an all-or-nothing situation Allon Mureinik - Retro Testing 5
  6. 6. One baby step at a time Allon Mureinik - Retro Testing 6
  7. 7. Refactor, refactor, refactor ● ● Your first task would probably be to do some refactoring Resist the urge to improve the code ● ● Frankly, this step may make the code look worse Your only goal here is to create an opportunity to write tests Allon Mureinik - Retro Testing 7
  8. 8. Refacroting with no tests is like... Allon Mureinik - Retro Testing 8
  9. 9. Example : Bad Code Allon Mureinik - Retro Testing 9
  10. 10. Some minimal refactoring Allon Mureinik - Retro Testing 10
  11. 11. Now we can start writing tests... ● ● Now we have the tools to separate external resources from logic There are a couple of ways to do so: ● Override the relevant methods in your test ● Use Mockito/EasyMock to spy the tested object ● Use @Rules to set up common mocking once Allon Mureinik - Retro Testing 11
  12. 12. I @Spy With My Little Eye Allon Mureinik - Retro Testing 12
  13. 13. Some more refactoring Allon Mureinik - Retro Testing 13
  14. 14. Let’s modernize our code Allon Mureinik - Retro Testing 14
  15. 15. But how can I write asserts? ● Overriding, mocking and all that jazz are fine and well ● But any test boils down to writing an assert... ● ... and I have no idea what this function is supposed to do ● Remember this is a legacy system ● You may not need to test it for correctness ... ● Just for backwards compatibility Allon Mureinik - Retro Testing 15
  16. 16. Allon Mureinik - Retro Testing 16
  17. 17. The real challenge is changing mindset ● We can discusses refactoring till we’re blue in the face ● But the real challenge isn’t changing the way we code ● It’s changing the way we approach the problem Allon Mureinik - Retro Testing 17
  18. 18. It’s all too easy to slip back to bad habits ● This bug is blocking the release... ● It’s a ton of work to refactor this logic out... ● The rest of the code is bad anyway... Allon Mureinik - Retro Testing 18
  19. 19. Have the courage to stand up to excuses Allon Mureinik - Retro Testing 19
  20. 20. Questions? Allon Mureinik - Retro Testing 20

×