GUT script see other nodes on scene as nulls
Jeremi360 opened this issue · 4 comments
Versions
(list all versions where you have replicated the bug)
- Godot: Godot 4.2.2
- GUT:9.0.0, 9.2.1
- OS: Linux Arch
The Bug
If I try to acess nodes in scene script see them as nulls.
This tests should be fails:
Steps To Reproduce
- Crate scene with some node other that root node
- Add GutTest node to scene
- Try to acess any node in scene from GutTest script
4a. See thatassert_null(node)
passes, when it should fail
4b. See that script crashes when you want for exampleassert_true(some_node2D.visible)
,
assome_node2D
will be seen asnull
Minimal Project:
It appears you are trying to create a scene that tests itself. You should not be using test scripts (extends GutTest
) as scripts in nodes. GUT instantiates all test scripts and then runs the tests inside (methods beginning with "test_"). There is no need to make a scene for tests to exist in. Rather, you should be creating instances of things to test inside your test script.
I understand this was just a sample, but to be clear, you should be testing things that are not in the Test
directory. For the example below I'm using a hypothetical player scene at scenes/player.tscn
.
extends GutTest
var player_scene = load('res://scenes/player.tscn')
func test_can_make_one():
var inst = player_scene.instantiate()
assert_not_null(inst)
func test_health_defaults_to_100():
var inst = player_scene.instantiate()
assert_eq(inst.get_health(), 100)
func test_can_set_health():
var inst = player_scene.instantiate()
inst.set_health(30)
assert_eq(inst.health, 30)
@bitwes It seams that it works when I crate scene in runtime in small project.
Now I try this aprouch in my other project.
My bad now I saw that in my orginal project exports that was poting to other nodes become empty after I turn them in to scenes, so I close this.