TDD is fun because it goes so quickly. Write a test, make it pass, refactor, run more tests.
I love the flow. I love adding a new interface and using it without worry about implementation. I love knowing after I make a new test, something in the app is different and it works. I love living in the tests and only running the application before checking in.
However, the moment the tests slow, the practices start to slip...
- Writing code and verifying it works by launching the app, then creating the tests
- Making the test pass before verifying it failed.
- Not running all the tests before check in.
- Not refactoring because it takes too long
- It stops you from working close to 5 because you don't want to wait for the build
- Not adding tests at all because you don't want to break the build and don't want to wait to find out
- It ruins all the fun.
So, how do we keep our tests running quickly?
- Mocking. Reduces the amount of time spent creating dependencies and their dependencies and the rabbit hole of dependencies that nobody can even see.
- Use a one to one ratio of test assemblies to application assemblies -- don't waste time waiting for things to build that you're not testing.
- Keep interfaces and implementations in separate assemblies. Dependents should only be recompiled if the contract changes, not the implementation. This allows you to complete the usage of a change, without worrying about the implementation. Sure, you can just resharper, but are you really going to add tests for a new method right now?? If you do, you break the rhythm, if you don't, you have to remember, somehow, that there is code that needs to be implemented somewhere that your tests won't pick up... you'll start thinking about the implementation or just forget and break the app without anyone knowing.
- Simplify. Keep tests short. Only create items in setup that are used in all tests. Avoid factories for creating concrete classes because they hide dependencies and make it too easy to use real implementations instead of mocks. Avoid repeating yourself in tests, don't assert the same thing twice, it doesn't help to have the same failure twice but it does slow everything down.
{ 0 komentar... read them below or add one }
Posting Komentar