Should unit test stubs/collaborators be "final" constants or just regular member variables? I have not been doing this but now my mentor wants me to do it and it feels like a major change. In this case I am talking about simple primitive types, String, and other already immutable object types.
He tells me that he "follows Java conventions" and, in a unit test, we should always put a "final" modifier on test stubs so that they are not changeable within the unit test nor by outside classes trying to modify it.
When I browse the internet, less than 5% of Mockito examples show the usage of a final modifier and rarely are those examples explaining why that is necessary. I can see why you might want a final modifier liberally within a non-test object that you mean to be immutable in some way.
But on a unit test is this necessary when the scope of the code might only be a few lines, and the variable is never changed outside the test method?
Aucun commentaire:
Enregistrer un commentaire