Unity Test Runner uses a custom NUnit framework dll. Does it also use a modified runner/adapter?

Hi all!

I’m getting close to getting my Unity unit tests running in Visual studio. I finally have my unit test project outside of Unity’s project directory, and so Unity no longer manages changes to the csproj file. My unit test csproj references unity’s modified NUnit framework dll, and the unit test dll builds successfully to the directory the Visual studio’s Test Explorer expects (bin/Debug). It seems I’m down to one last thing to get the tests to run…

Visual studio’s Test Explorer window successfully discovers and displays all of my unit tests, but when I run any of the tests, it says in the visual studio tests output window:

---------- Starting test run ----------
Not all tests from the test run selection could be discovered.
========== Test run finished: 0 Tests run in 22.4 ms (0 Passed, 0 Failed, 0 Skipped) ==========

So it seems the run-time test discovery is failing. My project is set up to reference the Nunit3 test adapter so that visual studio can run the tests. I’m thinking that perhaps this is the source of my test discovery error. Does Unity’s custom NUnit implementation also use its own custom test runner/adapter? If so, where can I find/reference it?

Thanks!

@garrett_b

Sorry for the confusion. The Test Explorer does not support Unity projects right now. It’s something we are actively working on. Visual Studio for Mac is planned to get the feature to discover, run, and debug unit tests in Unity projects in the next version (8.9) and Visual Studio is planned after that. For now, you would have to use the Test window in the Unity Editor to run the tests.

In the meantime, I would love to chat with you about your needs with unit testing. I’d also love to get feedback on our current plans and show you some early changes. If you’re willing to help, please send me a message here and I’ll follow up.

1 Like

Hi John!

Visual Studio Test Explorer support would be very useful to the team I am working with. Our team members each like using different test runners specific to their IDE of choice (Visual studio Test Runner, Resharper Test Runner, and Rider). In a perfect world, each member of my team would be able to run our Unity tests without having to open unity.

I would love to see the plans to support Unity’s tests in the Test Explorer, and give feedback.

JetBrains Rider already supports Unity tests (https://www.youtube.com/watch?t=527&v=h564F6pLOsE).
JetBrains dotCover support also coverage on CI.
As for JetBrains ReSharper, we’d like to make it compatible with VSTU, when it becomes ready.

1 Like

Note that for any test which interacts with the Unity API, it will always be necessary to have Unity running in the background. So “without having to open Unity” is probably never going to be the case.

There might be some improvements that could be made if we know that your tests are not referencing Unity API (e.g. if they are in an assembly that we know does not transitively reference UnityEngine.dll/UnityEditor.dll), but this isn’t something on our roadmap as a priority right now.

@superpig , that’s good advice. I’ll have a glass right now!

My use-case is likely different than @garret_b’s, but for me having unity open is not a big deal, it’s more about being able to remain focused on one development-environment.

3 Likes

This is not implemented yet, right? Did anyone find a workaround in the meantime?

Any news on this?

1 Like

Not needed on my end anymore. Switched to Rider some time ago.