Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it okay to rewrite unit tests?

Tags:

unit-testing

I am still learning OOP, and each day I discover something foreign. So when writing unit tests, it looks like it's common to have function names, and the program design in general, already defined. "Test this factory or that dependency container to see if it works as expected", for example.

Being a learner, I am pretty sure I'd want to change a lot of things, from function names to the structure of the code to what the functions do themselves, over time. Obviously, this would mean rewriting the tests to make them pass. Did you face this problem? A few things I read speak like it is taboo to touch tests once written, so how do you solve this?

like image 434
Aditya M P Avatar asked Jan 27 '26 03:01

Aditya M P


1 Answers

it is taboo to touch tests once written

This is total nonsense, of course. Time passes, things change, code evolves, tests need to be touched. Feel free to amend and rewrite tests, but be careful to not accidentally lose functionality in the process (when rewritten version does not test cases that previous version did).

For me this problem simply doesn't exist.

like image 199
Sergio Tulentsev Avatar answered Jan 28 '26 21:01

Sergio Tulentsev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!