Have created an android test project and currently trying to write android unit tests
now if you have a bunch of classes whose methods you are trying to test and you’ve been good and applied the principle of least access and made all your member variables private how do you then write effective unit tests?
In other words, my unit tests sit in a class outside of the class i am trying to test, so I can’t access any of the member variables in my assert statements
is there a workaround for this scenario where you want access to everything for testing purposes
please don’t tell me i have to write getters and setters for every member variable just so I can write some unit tests
(thinking about it, this is more a Java question than an android specific question)
Interesting question… Although you might have to write getters/setters for every member variable. It could be worthwhile to put them inside a subclass that you only use for your testing, so you can easily preserve encapsulation in your production code.
That’s the best solution I can think of.
EDIT: Or you could make a duplicate class for testing, where you do a quick replace all ” private ” with ” public “.