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