- Home /
How to trigger Update() method in tests?
I am trying to trigger the Update()
method of one my components in a unit test:
[UnityTest]
public IEnumerator SweetTest()
{
GameObject gameObject = new GameObject();
ElevatorController elevator = gameObject.AddComponent<ElevatorController>();
// Skip frame to trigger ElevatorController.Update()
yield return null;
But my Update()
method is never called :/
Any ideas?
Is this an editmode or a playmode test? Update is never invoked while in editmode.
Ah I see, that would be the problem, I'm in in editmode :/
Cool, Update()
is hit now that my test is in playmode. If you chuck your comment in an answer I'll accept it :)
Answer by Warnecke · Apr 24, 2019 at 07:41 AM
It needs to be a PlayMode test, as the Update method is only invoked in PlayMode tests and not in EditMode.
Answer by Jeezker · Apr 24, 2019 at 12:36 AM
Put the content of the update in a separate method, and then in Update you will only have that SeparateMethod() called. Now just call SeparateMethod() in the test. Make sure it is public. Also if you need it called multiple times in your test, ust put it in a for loop :) Good luck with your game
Your answer
Follow this Question
Related Questions
Variable value not updating in test script 1 Answer
Executing the game without render 0 Answers
Display one of prefab child 1 Answer
Updating Taken Pictures in Game 1 Answer