Creating mock 'stubs' #321
-
Hi, I'm trying to write some unit tests that should basically 'intercept' some file system operations. I have a function that has some logic in it that needs testing, which includes calling a locally instantiated ConfigFile's save() if a certain condition is false. However, I can't seem to find a way to mock that save function to not save an actual file to the system. So basically I'm trying to:
I tried to look at the 'mocks' documentation, but couldn't figure out a solution (especially since the config file is instantiated within the function's scope). Any suggestions on how I can implement this other than making the config file variable scoped 'publicly' to replace with a mock object in my class? edit:
I get an error saying |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I assume you are using Godot According to the Godot core developers, overwriting core functions was a bug. |
Beta Was this translation helpful? Give feedback.
Hi @bugbountyguy
I assume you are using Godot
ConfigFile
, the core functionsave
.With Godot version 4.x, the GDScript has been rewritten so that overwriting a core function is no longer possible, which breaks my mock implementation.
For more details, see #42
According to the Godot core developers, overwriting core functions was a bug.
To solve this problem, I have some ideas, but the implementation will take some time.
I have checked the GdUnit4 documentation, and I am missing this important information about mocking core functions, I
will add it.