A test runner implementation for the NUnit Framework
If you'd like to just see some examples in action simply clone this repo and open the project in the latest Mono version of Godot.
Note: You may need to open the project, run it with F5 or F6, quit Godot, run git reset --hard, then run it again. This is due to inspector variables disappearing without a build of the mono assembly available. godotengine/godot#15371
The current setup for using the test runner is quite easy.
1. Copy the "GodotTestTools" folder
First, you can use it in your own project by either copy-pasting the GodotTestTools folder into your own project, or if your more sofisticated you can use this as a subrepository.
2. Add the GodotTestTools.csproj to your Godot project
In MonoDevelop:
- Open your Godot game project's .sln file
- Right click on the solution and choose "Add > Add Existing Project..." and then find and add the "GodotTestTools.csproj" project
- In you game project, right click on "References" and select "Edit References..."
- Click on the "Projects" tab and then click the checkbox for GodotTestTools
(Note: I don't typically use Visual Studio, if someone wants to provide instructions for VS, feel free to contribute)
3. Call the test runner from your code
Once you begin to write your code that will use the test runner, such as the examples below, make sure that the method you use has the async
keyword.
It can currently be used in one of three ways:
- Run the test runner and collect the results at the end
- Run the test runner and get live results via a callback
- A combination of 1 and 2
Example of option 1
async public override void _Ready()
{
TestRunner testRunner = new TestRunner();
int passed = 0;
int failed = 0;
await testRunner.Run();
TestResult[] testResults = testRunner.TestResults;
foreach (TestResult testResult in testResults)
{
if (testResult.result == TestResult.Result.Failed)
{
GD.Print(testResult.classType.Name + "." + testResult.testMethod.Name + "\n" + testResult.exception.Message);
}
}
}
Example of option 2
async public override void _Ready()
{
TestRunner testRunner = new TestRunner();
int passed = 0;
int failed = 0;
await testRunner.Run((TestResult testResult) =>
{
if (testResult.result == TestResult.Result.Failed)
{
GD.Print(testResult.classType.Name + "." + testResult.testMethod.Name + "\n" + testResult.exception.Message);
}
});
}
To run, add a node to your scene and a C# script that contains whichever method you decided to use from the examples in the Setup section.
Next, simply hit F6 to run the scene you just created.
For now, the only rules for contributing are:
- Follow the normal casing rules for C#.
- Indent using tabs, not spaces
- Use uncuddled curly brackets
- If you aren't sure about something, please open an issue and ask :)
And... thanks!