I need to simulate a button click in the Unity unit test, so that the button event handler worked and I compared the results. I tried:

GameObject facebookBtn = GameObject.FindGameObjectWithTag("Player"); // Кнопка bool res = ExecuteEvents.Execute<IPointerClickHandler>( facebookBtn, new PointerEventData(EventSystem.current), ExecuteEvents.pointerClickHandler); 

As far as I understand, pressing works because res = true , and the button handler does not work. I think this is due to the fact that this is done in editor mode, although Unit tests are not performed differently in a unit. I also get the error:

Ignoring menu item NGUI because it is in no submenu.

Has anyone come across something similar?

    1 answer 1

    If the click itself is not important to you, but the method, you can call the method itself.

    If you need exactly imitation of the user's actions, then it is better to imitate her.

    If the button on the keyboard:

    http://answers.unity3d.com/questions/588786/is-it-possible-to-simulate-a-keypressinput-in-code.html

    If you need to simulate a mouse on the NGUI button in Unity3d:

    http://answers.unity3d.com/questions/564664/how-i-can-move-mouse-cursor-without-mouse-but-with.html