8 ms·
I gave an internal talk the other week on "Writing Highly Testable Code". I created this GitHub repo to use as my source material. https://github.com/ryanrodem
by hnrodey 6y ago
I gave an internal talk the other week on "Writing Highly Testable Code". I created this GitHub repo to use as my source material.
https://github.com/ryanrodemoyer/writing_testable_code https://github.com/ryanrodemoyer/writing_testable_code
I created a cheesy pneumonic device to help remember the four principles.
La.S.I.C.
1. Loosely couple your code from the entry point.
* Entry points are consoles, apis, services, GUI's, etc.
* The entry point always performs some type of setup or initialization.
2. Simultaneously write code and write test.
* Will quickly discover what designer patterns are easy to easy, and which suck to test.
3. Isolate dependencies using classes and interfaces.
* Use classes and interfaces to abstract/isolate/wrap away behavior with dependencies.
4. Constructors are for declaring dependency needs, not initialization!