I created a script for my Unity game managing the hover state of the gameobject the script is attached to
public sealed class HoverStateController : MonoBehaviour
{
private void OnMouseOver()
{
UpdateEntityHoverState(true);
}
private void OnMouseExit()
{
UpdateEntityHoverState(false);
}
private void UpdateHoverState(bool hovered)
{
// ... modify the state ...
}
}
I know that I should not try to test private methods because there is no need for it, I can check the result of the public service (Should I test private methods or only public ones?).
The thing is that the logic in UpdateHoverState
is testable very easily. So I could
- not test it, because it's private
- make the method public and test it, but access modifiers should be as limited as possible, so this breaks a convention (Access Modifiers - what's the purpose?)
- perform a
OnMouseOver
andOnMouseExit
by triggering something
I would prefer the last one but I don't know if Unity offers a way to trigger those methods. Is there a way to create a mock which calls them internally?