The Day TDD Started Working for Me
I've always agreed that Test Driven Development was a good idea and I should be doing it. But it's hard to do on top of learning new tools. And it's hard to do for GUIs. So it never quite happened.
However, after I worked with React and Redux a bit, and after doing a couple hello-world tests with Jest, it all fit together and actually made coding easier and more fun.
These were the parts that came together to make it work:
So now the flow of events and data into the Redux store is all testable pure functions. And the flow of data almost to the UI is testable pure functions.
When all of my tests are green, anything that's broken in the browser is probably a simple typo in my JSX or something equally easy.
And now I have the advantages of TDD and can, for example, reorganize something in the shape of my Redux state and follow the change through the code by making all the newly-red tests green. That's easy. I no longer have to try to keep the Entire Structure of Everything in my head to make it all work again. Wheeee! :-)
However, after I worked with React and Redux a bit, and after doing a couple hello-world tests with Jest, it all fit together and actually made coding easier and more fun.
These were the parts that came together to make it work:
- Jest: Jest is included with create-react-app and is stupid-easy to start using.
- The Redux reducer, or functions used in the reducer, have to be pure functions and are therefore stupid-easy to test.
- I pulled some functions out of Redux Container mapStateToProps. These are also pure functions.
So now the flow of events and data into the Redux store is all testable pure functions. And the flow of data almost to the UI is testable pure functions.
When all of my tests are green, anything that's broken in the browser is probably a simple typo in my JSX or something equally easy.
And now I have the advantages of TDD and can, for example, reorganize something in the shape of my Redux state and follow the change through the code by making all the newly-red tests green. That's easy. I no longer have to try to keep the Entire Structure of Everything in my head to make it all work again. Wheeee! :-)
Comments
Post a Comment