Search code examples
androidunit-testingmvpandroid-mvptest-coverage

Should unit tests cover constants changing?


I am creating a unit test for my presenter. I have 2 constants for a ranges which definitely can be in future changed to a requests from server. So I wrote all my code in the way that it will work with any value of this constants.

And now I have possibility to change this constants for unit test. I'll just add some functions with return this constant ranges and the mock this functions. But I should I do it.

On the one hand changing constants for testing gives me confidence that my code work with any value. But on the other hand unit tests will not cover that constants do not changed.

So in other words, should unit test cover constants value?


Solution

  • Certainly you could do that testing right now, but I recommend following the YAGNI principle: Don't test it now, you may never make the change. However, once you turn these constants into variables, you would have to extend your test suite. Chances are that your test suite will need maintenance anyway, but to be sure you don't forget it, add a comment to the constants or use some other form of reminder...