How to write unit tests for scripts with @onready
vars?
#330
-
Hi there, I've got a new script that I want to write unit tests for, but any time I write a test for any function that uses a variable from For example, if I have:
and try to run a function that uses values or something from How can I setup my unit tests to work with these? I couldn't find any examples of this or mentions of it in the documentation so thought I'd come here to ask :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @bugbountyguy i guess you have a scene with attached script you want to test. The annotations are set when a node is added to the scenetree.
b) Load your script you want to test and set the
|
Beta Was this translation helpful? Give feedback.
Hi @bugbountyguy i guess you have a scene with attached script you want to test.
The annotations are set when a node is added to the scenetree.
So you have two options.
a) load your scene and add it to the test-suite, with
add_child()
the_ready
step is executed, and you should have a full instantiated model.Please note that ALL dependencies of the scene are loaded here.
If you only need a part of the dependencies, you should rather mock the relevant components. See option b
b) Load your script you want to test and set the
_player_model
manu…