3 Unexpected benefits of writing integration tests
And no, not better code quality, it’s much more impactful than that
I love writing tests for my Flutter code.
Even in the early stage. But I didn’t know I’d get so many unexpected benefits from it.
I’ve been a unit tester for almost 10 years, but I can now confidently say that the most impactful form of testing is integration testing.
Where unit testing helps confirm individual pieces of code work, integration testing helps you confirm if your app still works.
The crazy thing is, you only need 1-4 tests to cover all your critical functionality
And best part of it is, these tests are actually small and easy to write. Here’s an example of some I wrote recently.
In this post you’ll learn:
Why I started writing integration tests
The biggest benefit you’ll experience
How these tests impact your team
How we can work together to get you started
Why I started
I haven’t always used integration testing, in fact, I only started writing them in 2020. But since I started I’ve experienced a major boost in productivity and more importantly a boost in the amount of focus time.
What I struggled with the most, is when I run an app to check code that I just added, but then something else ends up breaking. This means I need to context switch, understand why I can’t test my code, fix the issue that’s causing it, and then start testing my code.
This literally cost me hours per day, but more impactful than losing hours is losing my motivation to properly test the code that I just wrote.
Sometimes we spend hours writing code before confirming it works, so when we do want to confirm it works, we don’t want something we didn’t touch to cause an issue for us. Personally, it’s very deflating and drains a lot of energy and motivation, to the point where I start to procrastinate to avoid fixing code I didn’t break.
Integration testing helped me get out of that scenario. Simply put, an integration test is a shortcut to guarantee the app still functions. It’s a quick check that allows you to say, “everything still works, let me now test my code out”.
The biggest benefit
Imagine you had a button you could press to tell you if your app still works as expected.
Not if the code in your app works, but the app itself. The authentication, the request for data from the backend, the model serialization, if the backend is still up, if the data format is still as expected on the backend, every critical part.
That would be amazing right?
Well, that’s exactly what integration tests are. Literally, a keyboard shortcut you can press that will tell you if your app still works. That is the benefit of immediate feedback, and it’s the biggest one we get.
Before you actually run the app and log in, navigate around, and tap around to get to your code. Before any of that, you can make sure the app still works as expected. Better yet, before the developer that actually broke the code pushes that broken version they can “push that button” and catch their mistake early.
This takes us to the last 2 benefits.
Team Impact
Once you add this to your codebase your entire team gets the “does this work” button.
The second most impactful benefit of integration testing is the ability for everyone to check, instantly, if their changes caused anything to break. So the scenario that drained my energy, made me lose hours, and caused me so much deflation, is avoided.
Before the code is merged, we push the “does our app still work” button and make sure we don’t affect our team’s focus and effectiveness.
Which is our final benefit, workflow improvement. We all have our workflow that we follow.
Write code
Run the app
Manually go through and test your code.
But sometimes that process is blocked halfway through, then you have to unblock yourself before you can continue your work. But by running integration tests first you find out about that blocker even before you run the app. Saving you a lot of energy and focus power.
Conclusion
This is honestly one of the best additions to my Flutter toolset and has helped me build faster, get more done, and have a higher level of focus during my own coding and testing cycles.
If you or your team want help setting up integration let’s do a pair programming session together. There are only a few slots left.
I hope you enjoyed this,
Good luck!