I am required to create unit tests in Flutter and the problem is that I don't really get what they are for, how they make an app better or safer? Also I would be happy if you gave me the source where I can learn them
CodePudding user response:
this answer might be not 100% accurate because i tried to make it simple as possible to make you get started tests will not only help you make your application stable it will force you to write the code in a better way
for example :-
you cant tests this method since it depend on another class instance
and it creates it within the method this is call coupling
and it will prevent you to make some test cases for this so you have to go back an decouple these dependencies to be able to test it which will make the code safer and cleaner
also if you add a feature or fix a bug you might change the code behavior for instead of throwing some error you return a false or you calcurlate some thing un expected way or any thing even smallest changes code change the behavior which will lead to breaking some thing in the end
if you working on a tested project , simple use the command flutter test
to make sure every thing is working as expected instead of going on production and find out you have bugs over a silly mistakes
another way to imagine it like if you like the IDE to find your syntax errors while writing the code or waits until you push your code and the reviewer sends you back because you forgot a ;