I have begin incorporating unit tests (junit 4.12
) into my Android project.
One scenario I have encountered is determining whether a view has been added correctly.
For example in my ViewToTest
class:
private TextView _text;
/**
* Shows all text.
*/
public void showText()
{
addView(_text);
}
/**
* Hides all text.
*/
public void hideAllText()
{
removeView(_text);
}
From what I understand with unit testing I am supposed to test the behaviour not the method, but in this case, the behaviour is the method (or correct me if I am wrong).
My question is 2 parts:
- How do I test that
_text
was added to parent view? - How do I handle the above scenario when the view is private?
For part 2 I know I could create a getter for the view but to me that defeats the point. I would only be adding that for the test!
All advice welcome thanks!