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

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:

1 Like

Did you manage to find anything that works ?

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: GitHub - Unity-Technologies/mono: Mono open source ECMA CLI, C# and .NET implementation.

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?

anyone managed to get code coverage in Unity yet?

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.

Seltzer, any progress on that? :slight_smile:

Just wondering if anyone was able to find anything that works yet.

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.

I look forward to have this feature inside Unity Test Tools.

Unity test tools is deprecated as most of its functionality is already built into the engine.

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.

16 Likes

We live in exciting times :slight_smile:

2 Likes

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://discussions.unity.com/t/650045

Thats great news.

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

1 Like

@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.

10 Likes

Nice! Looking forward to this.

Please keep us updated on this thread on how things are going on.

Thanks.

@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…”

@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.

6 Likes

Great work! :slight_smile: