Statics are not getting covered

Hi,

Declaration of statics are not getting covered but where they are used are. Is that a code coverage bug? Please see the examples attached.

Unity 2023.1.17f1
Code Coverage 1.2.5

Cheers



Hi @amrocha

Static fields are initialized only once, when the type is accessed for the first time. Behaviour you’re seeing can happen if statics were initialized before starting coverage session, as then initialization code would not run and as a result those lines would appear as uncovered.

If you would like those lines to appear as covered, try calling EditorUtility.RequestScriptReload() after starting code coverage session but before running your tests. Domain reload will reset scripting state so accessing your static types in your tests afterwards should re-initialize them and record those lines as covered.

Hi @JuliusJ

Thanks for your reply it makes total sense. Unfortunately, Unity version 2023 doesn’t have the EditorUtility. Do you know if it was removed only or if it got replaced with something else?

Thanks

Hi @JuliusJ

I have tried reloading the domain with 2022 but still the statics are not being accounted as covered. Is there anything else I could try?

Thnaks

Unity 2023 has that class.

https://docs.unity3d.com/2023.1/Documentation/ScriptReference/EditorUtility.html
https://docs.unity3d.com/2023.2/Documentation/ScriptReference/EditorUtility.html

Hi @Ryiah ,

It says unsupported for 2023

It’s just saying the version of Unity is not supported and not being updated. It doesn’t mean the class is not there

It occurred to me after I posted that you might be referring to that. That line is a poorly phrased way of saying that Unity 2023.1 and 2023.2 no longer receive updates. Every entry including the most fundamental classes have that message on unsupported versions.

https://docs.unity3d.com/2023.1/Documentation/ScriptReference/MonoBehaviour.html

9930138--1436802--upload_2024-7-8_21-52-52.png

oh I see thanks @spiney199 and @Ryiah , weird that VS code didn’t allow me to use it as well. I will try again.