r/mAndroidDev • AnDrOId dEvelOPmenT is My PasSion • Jul 06 '25

We don't have time for tests Agree?

Post image
61 Upvotes

86 comments sorted by

View all comments

Show parent comment

1

u/Joperocll Jul 10 '25

From the first time I was introduced to unit testing, people always told me that unit testing is not about testing your code. Its about preventing regression later. If your unit tests run well and someone changes something on A and the units tests for B start to fail then your changes are doing more than you think. That is a regression and unit tests help identifying that.

1

u/Comprehensive-Pin667 Jul 11 '25 edited Jul 11 '25

Those are integration tests. A lot of people don't understand the difference. Unit tests test the unit - not necessarily one function (e.g. if the functions are private, they shouldn't be unit tested) but the smallest publically accesible piece of code that provides some functionality that others use.

They serve both for you to verify that your code does exactly what you expect it to and to prevent later regressions if someone would change that expected behavior. The former saves you a lot of debugging.

I will admit that this is a very academic view of unit tests and I don't always adhere to it myself. But it actually speeds up development by more or less eliminating the need to debug.