Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Unity Test Tools - please recommend code coverage tool for unit tests

Discussion in 'Testing & Automation' started by dvan, May 20, 2015.

  1. dvan

    dvan

    Joined:
    Aug 9, 2014
    Posts:
    4
    Can anyone recommend a good tool for measuring code coverage by unit tests with nUnit?

    The Unity Blog has a good post showing how they measure various aspects of code coverage (decision, condition, condition/decision, and function coverage) in their c/c++ framework (link). Something similar to that functionality in a C# project would be awesome.

    So far, I have found these tools that work with mono but am yet to try them:
     
    Last edited: May 20, 2015
    Arkade likes this.
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Did you manage to find anything that works ?
     
  3. Seltzer

    Seltzer

    Joined:
    Jan 21, 2015
    Posts:
    5
    I also came across monocov as a potential solution. I haven't found examples of anyone else doing it yet. However, I did find that monocov is included in Unity's fork of mono, though the repository looks to be a bit dated: https://github.com/Unity-Technologies/mono

    In any case, it seems to boil down to whether the versions match up, and how to go about running mono on a Unity editor test (at least that's my ideal use-case). It seems like a potential crapshoot. Does anyone here have more in-depth knowledge on how Unity runs mono?
     
  4. mle_samlabs

    mle_samlabs

    Joined:
    Jul 14, 2016
    Posts:
    2
    anyone managed to get code coverage in Unity yet?
     
  5. Seltzer

    Seltzer

    Joined:
    Jan 21, 2015
    Posts:
    5
    I haven't managed to get anything working yet. I'm going to try out the dotCover CLI in Wine next. Seems like a pretty big ordeal just for coverage, but it works on Windows, and I know that someone has successfully automated it for a Windows-based Unity CI server. I'll post my findings if I come across something more conclusive.
     
  6. Xanewok

    Xanewok

    Joined:
    Mar 28, 2017
    Posts:
    1
    Seltzer, any progress on that? :)
     
  7. kdragos

    kdragos

    Joined:
    Jun 25, 2016
    Posts:
    13
    Just wondering if anyone was able to find anything that works yet.
     
  8. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    If you're using Visual Studio, there's dotCover which is great. i used it in the past and it worked great. The only limitation is that you'd probably won't be able to run tests that are executed inside Unity since it is the test runner in VS that actually executes them, and not Unity.
     
  9. schifers

    schifers

    Joined:
    Jul 22, 2013
    Posts:
    1
    I look forward to have this feature inside Unity Test Tools.
     
  10. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Unity test tools is deprecated as most of its functionality is already built into the engine.
     
  11. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    We are working on a Code Coverage solution that will work in your projects. It will be released as a Unity Package. Once you add that to your project you will get a new entry in Preferences with some coverage options.



    Initially, we will report coverage using the OpenCover format, but support for more formats is planned to be added later.
     
    Arkade, Mikael-H, PaulUsul and 13 others like this.
  12. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    We live in exciting times :)
     
    GarthSmith and hippocoder like this.
  13. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    Thank you so much, really. In my organization I am in charge of the code base of the whole team and even having many tests done, without code coverage I am not able to see if I leave certain paths uncovered.

    A couple of years ago I suggested in the forum to add it but they didn't listen to me.

    Original thread: https://forum.unity.com/threads/tes...de-tests-and-code-coverage-with-nunit.447941/
     
  14. Sharfan

    Sharfan

    Joined:
    Dec 20, 2018
    Posts:
    1
    Thats great news.

    @ElvisAlistar is there an estimated date/period that this package will be released?
     
    OleJuergensen likes this.
  15. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    @Sharfan We're still assessing the readiness of this. We could be doing a Preview release of it sooner or we could wait and work on it more and get something more production-ready out later. What we don't want to do is ship a Preview version of it and then never get to polish it later. I ask for your patience while we're looking at it from all angles. I know this has been a long-awaited and much-requested feature and we're working towards bringing it to you.
     
  16. cbauman

    cbauman

    Joined:
    Aug 29, 2011
    Posts:
    17
    Nice! Looking forward to this.
     
  17. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    Please keep us updated on this thread on how things are going on.

    Thanks.
     
  18. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    @ElvisAlistar is it possible to follow the development of this somehow? Is it openly available in a repo?

    Regardless, this really made my day! Best of luck in the development of this very important feature. For industrial customers this is really critical. Where I work code coverage of your work is a key performance metric so it sucks for the people who work with Unity who always have to defend themselves when SonarQube says 0% that "no it's really hard to measure in Unity…"
     
  19. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    @Mikael-H we're getting close to making a public preview version available and it will be announced in a separate thread on this forum when ready. The tooling is going to be a package, which means that you'll be able to see and modify its source code.
     
  20. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    Great work! :)
     
  21. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    a436t4ataf, Mikael-H and GarthSmith like this.
  22. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87