mercredi 28 octobre 2015

Local Variables or Fields | Best practice after Unit-Tests | Clean Code

So I am currently writing Unit-Tests for a MVC Spring Webproject. The intention of these Unit-Tests, is to get Clean Code Guidelines, in order to approach Test Driven Development in the future.

The problem I have is, that currently many classes use local variables inside methods. This makes it impossible for me to mock them with Mockito and to ensure, that my Unit-test is isolated from all outside dependencies. (for more info: When to use when() in Mocktio)

But would it really be Best Practice now, to only declare fields? What I understand is, that fields can have the disadvantage, that they are too far away from where they are needed and that local variables are more secure.

Aucun commentaire:

Enregistrer un commentaire