Having a private String constant in a java class that is used in some methods, when I want to make the test for this class, I will have to hardcode the string constant in the test because its private in the class. But if in the future the string constant is modified in the class, I will have to modify in the test class too. I dont want to modify the visibility of this constant just for the tests to avoid this possible modification in the future. Is this thinking correct according to the TDD methodology?.
Thanks.
Changing visibility to package-private for tests should be fine. Still, it can be used in the same package, if some other developer is not aware he shouldn't do it. This can break stuff, if you change the value later on.
Better approach would be to use some abstraction to get this value, instead of using it directly. For example:
Now you can mock
valueSupplierin your unit tests. This allows you to changeSOME_VALUEhowever you like, without breaking existing tests, while still keeping it private.