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

Access violation in .NET C# unit test project #67728

Closed
unbornchikken opened this issue Oct 21, 2022 · 4 comments
Closed

Access violation in .NET C# unit test project #67728

unbornchikken opened this issue Oct 21, 2022 · 4 comments

Comments

@unbornchikken
Copy link

Godot version

4.0.0-beta2

System information

Windows 10

Issue description

I have a C# game with an added assembly for game logic. I've added a .NET 6 MSTest project to test game logic. So far so good, tests are running.

But I have a class that assembles geometries by creating Godot ArrayMesh instances. Once ArrayMesh's constructor gets called I get an Access violation error.

Steps to reproduce

The very basic repro is just create a .NET 6 console project, add GodotSharp 4.0.0-beta2 nuget package.

Program.cs:

using Godot;

new ArrayMesh();

Minimal reproduction project

No response

@raulsntos
Copy link
Member

The C# bindings just call the native C++ implementation so the Godot binary needs to be the entry point or the function pointers won't be available. You should be able to create a Game project that runs the tests though.

@unbornchikken
Copy link
Author

Ok, then my question is how should I create a game project that can run MSTest based unit tests? How should I run and debug my tests there? I just created a regular .NET 6 unit test assembly from Visual Studio, and tried to run my tests with VS integrated test runner.

@raulsntos
Copy link
Member

It would just be a normal Godot game project where the main scene runs the tests (e.g.: using the MSTest.TestAdapter package), then you should be able to collect the test results and print them in the console (e.g.: using GD.Print) and then you can exit using SceneTree.Quit which allows you to specify the exit code (0 when tests pass and non-zero when tests fail).

To run the game project from Visual Studio you should be able run and debug it like a normal Godot game project. Unfortunately I don't think there's an easy way to run the tests integrated with the Visual Studio Test Explorer other than maybe implementing your own test adapter but I'm not familiar with how that works.

There is more information about running unit tests in this related proposal: godotengine/godot-proposals#432.

@unbornchikken
Copy link
Author

Thats great, and working well, thank you.

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

No branches or pull requests

3 participants