Search Unity

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

Discussion in 'Testing & Automation' started by garrett_b, Dec 14, 2020.

  1. garrett_b

    garrett_b

    Joined:
    Oct 14, 2020
    Posts:
    24
    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!
     
  2. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @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.
     
    Mikael-H likes this.
  3. garrett_b

    garrett_b

    Joined:
    Oct 14, 2020
    Posts:
    24
    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.
     
  4. van800

    van800

    JetBrains Employee

    Joined:
    May 19, 2016
    Posts:
    73
    Vaupell likes this.
  5. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    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.
     
  6. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    @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.
     
    Extrys, John_MSFT and superpig like this.
  7. unity_146820BF26AE97E219E3

    unity_146820BF26AE97E219E3

    Joined:
    Oct 5, 2022
    Posts:
    5

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

    ClockStone_Helmut

    Joined:
    Feb 23, 2015
    Posts:
    12
    Any news on this?