Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Tests in Godot engine

Tags:

testing

godot

Soo I'm developing a game with the Godot engine and I want to create some test for the code to be sure that everything is working, I can't test the game with simple actions it takes 5-10 minutes. Is there a way to write tests ???

like image 293
Thanos Mourtzoukos Avatar asked Jun 08 '20 09:06

Thanos Mourtzoukos


People also ask

Does Godot use coding?

Godot offers five gameplay programming languages: GDScript, C#, VisualScript, and, via its GDNative technology, C and C++. There are more community-supported languages, but these are the official ones. You can use multiple languages in a single project.

What is unit testing software?

Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation. This testing methodology is done during the development process by the software developers and sometimes QA staff.


2 Answers

Have a look at GUT, the Godot unit test framework, or WAT.

Differences between the two, quoting WAT's author:

  • GUT runs in a scene. WAT runs in the editor itself.
  • GUT (last I checked) cannot handle creating Test Doubles that take constructor dependencies (as in it uses the _init method with arguments).
  • WAT has parameterized testing (so you can do the same test multiple times only needing to define the different set of arguments per run through).
  • WAT has a much larger range of asserts (I think)
  • WAT can intentionally crash a test script if one method fails (this isn't documented yet though).
  • WAT cleans up after itself with regards to memory. GUT doesn't. (Note: This was largely thanks to the recent method print_stray_nodes builtin to Godot that GUT didn't have during its initial creation).
  • GUT allows for inner test classes. WAT doesn't. However WAT has the "context" attribute attached to every asserts call so you can add sub-context to your describe() method context of the parent method.
like image 56
Thomas Avatar answered Oct 19 '22 09:10

Thomas


There is also GdUnit3 https://github.com/MikeSchulze/gdUnit3 ;)

It will release in upcoming version 2.0.0 with c#-beta support.

GdUnit3 is full integrated in the Godot editor with a UI inspector to navigate over your test results. Supports also automated testing by using the command line tool in a Github-Action

Feel free to give a try ;)

like image 28
Mike Schulze Avatar answered Oct 19 '22 11:10

Mike Schulze