Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run NUnit/XUnit tests in Godot process #58

Merged
merged 73 commits into from
Jan 21, 2021
Merged

Run NUnit/XUnit tests in Godot process #58

merged 73 commits into from
Jan 21, 2021

Conversation

van800
Copy link
Member

@van800 van800 commented Nov 9, 2020

Addresses godotengine/godot-proposals#432
Applicable to Rider 2021.1 and newer versions:

  1. Put RiderTestRunner folder with files from here to your own project.
  2. Use example in Different types of tests van800/godot-demo-projects#7 to see, what different types of tests can be done.

How it works (optional read):

  1. When user tries to run tests, the Godot plugin in Rider checks if is Godot
    return project.IsGodotProject() ? GodotTestRunnerHost.Instance : null;
  2. instead of running UnitTestRunner process, (which is nearly similar to NUnit-console,) we start Godot Game with a special Runner.tscn in commandline.
    var godotPath = myModel.GodotPath.Value.QuoteIfNeeded();
  3. Once the game starts
    https://github.com/van800/godot-demo-projects/tree/3b193ba6d6d3d5bac7ec2145cd5b4a0628d9202b/mono/dodge_the_creeps/RiderTestRunner
  4. It checks what came in commandline args and loads Rider assembly in the game
    https://github.com/van800/godot-demo-projects/blob/3b193ba6d6d3d5bac7ec2145cd5b4a0628d9202b/mono/dodge_the_creeps/RiderTestRunner/Runner.cs#L31
  5. Rider assembly does its thing to run tests and communicate with Rider and send it test results.

@van800
Copy link
Member Author

van800 commented Jan 19, 2021

I understand that for sure.

@van800 van800 changed the base branch from net203 to net211 January 20, 2021 13:35
@van800 van800 changed the title [WIP] Run NUnit tests in Godot process Run NUnit tests in Godot process Jan 20, 2021
@van800
Copy link
Member Author

van800 commented Jan 20, 2021

Planned to be published with Rider 2020.1 EAP1. Compatibility with Unity was resolved.
Coping scene and script to project should still be done manually. Those scripts were renamed.
https://github.com/van800/godot-demo-projects/tree/3b193ba6d6d3d5bac7ec2145cd5b4a0628d9202b/mono/dodge_the_creeps/RiderTestRunner

@van800 van800 merged commit baf8c27 into net211 Jan 21, 2021
@Flavelius
Copy link

The extra files would probably be a good candidate for a godot addon. This way they would be contained in a 'standard location', and the addon would even have the ability to open a socket or create some other additional form of communication channel with rider for other project file related tasks.

@alfredbaudisch
Copy link

alfredbaudisch commented Jul 6, 2023

Has anyone managed to make NUnit/XUnit tests work for Godot 4? Tried everything suggested, but there's always a different kind of error.

@geowarin
Copy link

geowarin commented Jul 6, 2023

Yes, Nunit tests work for me.
See : https://github.com/geowarin/GodotUnitTests

If you are using the latest EAP you can use this project as-is (with the test and game csproj cleanly separated from the sln), otherwise, use this commit: geowarin/GodotUnitTests@a4d2ac2

@van800
Copy link
Member Author

van800 commented Jul 6, 2023

Pure xunit works only to some extent, check the https://github.com/van800/godot-demo-projects/tree/net6/mono/dodge_the_creeps . But there is a wip on godotxunit port to Godot 4 fledware/GodotXUnit#20.

@theashtronaut
Copy link

I've not been able to get tests to work on Godot 4. I've switched to the NetCoreRunner files featured in
https://github.com/geowarin/GodotUnitTests
and also tried the one from
https://github.com/van800/godot-demo-projects/tree/net6/mono/dodge_the_creeps

The tests are not run and say inconclusive. The window pops up like before (in 3.x) but immediately closes.

I even tried the most basic test:

   [Test]
   public void Test1()
   {
       GD.Print("Test Hello");
       var main = ResourceLoader.Load<PackedScene>("res://empty.tscn").Instantiate<Main>();
       Assert.AreEqual(new StringName("Node3D"), main.Name);
   }

Using Godot Engine v4.1.stable.mono.official.970459615
JetBrains Rider 2023.2, Build #RD-232.8660.212, built on July 31, 2023
NUnit 3.13.3
Tried both dotnet 6.0 and dotnet 7.0, no differences.

The session file doesn't seem to throw and obvious to me errors.

2023-08-04-10-48-24-993___e770c8d2-def6-489d-8221-34afcbb5e532.log

Any idea on why it isn't working out for me? I'm sure I've done something wrong!

@jakeboxer
Copy link

@van800 thanks for your hard work on this, I've been using it to great success and we've got over 400 tests running in just a few seconds in Rider!

Unfortunately, I haven't figured out a way to run the tests from the command line, which means I can't get any CI up and running on GitHub or GitLab or anything. Do you know if this is possible currently? And if not, could you point me in the right direction for adding support for this to Godot myself?

Note: I'm jakecard on Discord if you want to talk it through there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants