Do you know of fast ways to test critical code in GDScript?
For a while now I wonder what is the best way to have unit-test-level tests within a Godot project based on GDScript. I couldn’t find much except maybe the Godot unit testing (GUT) plugin. I don’t see this topic discussed much at all, even tho I think there is reason enough to have some simple testing capabilities within Godot, and I believe it shouldn’t be hard to get these capabilities either.
My goal is to get very simple tests going for some simple aspects of the critical algorithms I need in a game. Here are some examples.
I might have a game put I want to make sure I parse simple math expressions the right way in GDScript: -2 - 0 * 21.
Or I have I want to test if my algorithm returns the right neighbors in a 2D-array, depending on the neighbor mask I use.
There is many more unit-testing examples, but I think these two show my idea.
There is unit testing for C++, C# or any other Godot extension, but I am rather interested in getting testing capabilities without the hassle of using any extension mechanism.
What I look for is anything, plugins, code-snippets or templates, discussion, advice.
I don’t believe code coverage is a big concern for video game development, but I think knowing the core functions of a projects work properly is very important sometimes and I want a fast way to have more confidence in my critical game code.
Any help is very welcome!
Thanks in advance!
P.S.: I created this under the General topic and not Help, because I don’t have a concrete Godot problem to solve. I hope that fits. If not, feel free to change it, I really don’t mind which category this goes by.
I prefer GDUnit4 because it has a few features I like that GUT does not. GDToolKit also has a number of neat features as well if you want to apply a more professional approach to your game development.
I wrote a whole tutorial on how to install and use GDUnit4 about a year ago. So feel free to take a look at that. It was a part of a series I was doing to teach people how to become professional developers through game development. (I’ve since abandoned it and learned a lot more about Godot.)
I was writing tutorials on how to learn development by learning game programming because I was going to sell it as a course. Each course was taking me about a week full time to write, and I realized it was going to be about a year before I had something. Plus I’ve learned how to do things better, so some of it was becoming obsolete even as I wrote. I decided to try and focus on making money by making games, and made all the articles I’d written free.
While I do like GDUnit, I don’t use it much in my day-to-day because Godot is really good about telling you when things aren’t working and no one is paying me to use it. If I were still working for a larger company or with a larger team where it made sense, I would.
However I do spend a lot of time building components for my games which I’ve open sourced. I tend to get a lot of testing on them using them, and people are starting to use my StateMachine, so I’m getting better feedback than I would with Unit tests. I try to keep things atomic, which helps. Plus, most of the bugs that pop up are visual or audio related and unit tests cannot tell me something looks or sounds funny.
That’s interesting! Is that helpful? I guess that is a topic on its own!
I would also always try to keep things atomic. But quite often I come across parts in the game logic which could be totally isolated. Even if I would brake them down into atomic steps, I could introduce mistakes in the abstractions I use to turn them into more atomic problems. In such cases I see unit testing as a quick way to not introduce more mistakes.
I will definitely try out some of the resources provided by you and @Toxe.
Should you compare the two I would also be interested in what you feel is missing in one or the other, as I have only used GUT and don’t really feel like I am missing anything, but on the other hand maybe GDUnit has features that would be nice to have.