¿Nos hacen los tests ir más rápidos? Mucha gente se pensará dos veces la respuesta a esa pregunta, cuando debería ser un rotundo y claro “sí”.Programadores de todo tipo intentan introducir el testing entre sus prácticas, pero no consiguen sacarle el beneficio esperado. Se sienten engañados ante todas aquellas promesas de refactoring seguro, de velocidad, y, en definitiva, de un código mejor.
20. Avoid logic inside tests
Conditionals: You don’t know which path the test
will take
Loops: you could be sharing state between tests
If tests have logic, who test the tests?
Problems
22. Be concise
Too much information in your tests make them
hard to read
Think about what details could you leave out
Assert messages help us highlight behaviour
Problems
24. Assertions
Use the name of the test for
explaining the feature that you are
testing.
Then use assert messages to clarify
what's the example under test and
why is that tested.
29. Building same objects
We depend on the stability of the constructor /
setter methods. If they change, we are screwed.
We are forced to pass all the parameters, even if
they are not important for the test.
Problems
44. Expressing the intent
"The refactoring technique
‘Extract Method’ is not
about saving lines of code
to make it shorter, but
about make the code more
readable"
45. Typing isn’t the bottleneck
"Programming is not
about typing... it’s about
thinking"
- Rich Hickey
49. Problems with Set Up
Move important code out of sight
Now you have to remember that the code was
there
Since code in setUp is generic for all test cases, you
lose context on why is that code there
Problems
53. Problems with Providers
Tend to make tests more complex
The most meaningful parts of the test (input &
output) are now outside the test
Usually end up more complex than you expected
Problems
72. Query
Queries return a value and
don’t change the observable
state of the system
Free of side effects
73. Test Doubles
Use stubs to force a query to return
a specific value so you guide the
execution path of the test
74. Test Doubles
Use stubs to force a query to return
a specific value so you guide the
execution path of the test
Use mocks to assert that a
command to another object has
been sent
86. Conclusions
Testing makes you go faster.
Throw some love to your tests.
If you find yourself going slower,
identify why.
TDD makes all of this much easier.