In this post, we’re going to talk about how testing can make your development experience faster.
Sometimes a feature you’re developing is time-bound. It's built around a slow external process. Every time you want to test a change, you have to make an expensive call and wait.
Instead of wasting time, you can use tests to automate and mock the slow parts.
Automate the workflow
Often times building a feature is the result of a series of incremental steps.
For example, let’s say you wanted to build a multistep wizard in a modal. The wizard is going to have five unique forms that are shown one after another. To build that form you might use the following steps:
Make a button to open the modal
Build a form in the modal
Add a next button
Build a second form for the next step
Repeat until all the steps in the wizard are built
Now, this might not sound difficult, but as you progress to the later steps, development slows down. To verify changes made to a later step, you have to enter information for the previous steps.
This is a tedious process that wastes a lot of time.
That said, it doesn't need to be a manual process. Instead, you can build tests as you develop the feature. The benefit is that automated tests are usually much faster than manual interactions.
You get feedback faster and can make corrections sooner.
Mock the slow parts
Having to wait on slow external dependencies is also frustrating.
It usually doesn't matter if the dependencies work during development. It's more important to have an accurate representation of what a dependency returns. Long-running background processes don't need to run every time you make a change.
Instead, mock these processes in your test suites.
You can move faster and rely on tests to verify each change. When you're confident the code is working, swap in the real implementation.
Document edge cases
Finding edge cases can be a difficult task.
You probably won't find every edge case on the first pass of a feature. Usually, it requires that you step back and think about how the feature will be used end to end.
Testing helps you start this process early.
When you write tests, one of the goals is to think about how your code will break. Writing tests to verify those cases leads to robust code that's better documented.
It’s almost guaranteed that you won’t get everything right when you first build a new feature.
You’re going to have to make changes to your code as stakeholders finalize the requirements. The problem is that changing code that isn't tested requires stricter regression testing.
How do you know that you haven’t broken existing functionality?
Unless the changes are trivial, you have to manually retest everything. Unfortunately, this is a huge waste of time. Instead, if you ensure you have automated tests, then refactoring becomes easy.
While it's not guaranteed you won't break something, you'll be more confident that your changes are safe.
Learn to rely on the automated test
I know testing isn’t everyone’s favorite thing to do.
But learning to test early can pay dividends throughout your entire developer career. You’ll write better code and be more efficient while doing it. Testing might seem like it’ll slow you down at first, but in the long term, it saves time.
Next time you’re building a new feature, try to leverage automated tests to speed up your development process.