docs.unity3d.com
    Show / Hide Table of Contents

    Class CodeCoverage

    Utility class for the CodeCoverage API.

    Inheritance
    Object
    CodeCoverage
    Namespace: UnityEditor.TestTools.CodeCoverage
    Syntax
    public static class CodeCoverage
    Examples

    The following example loads a scene, starts coverage recording, initializes a number of instances of a prefab, then pauses the recording to load another scene, unpauses the recording, initializes a number of instances of a different prefab and finally stops the recording. It also sets the verbosity level to Verbose, so all logs are printed to the editor log.

    using UnityEngine;
    using UnityEditor;
    using UnityEditor.TestTools.CodeCoverage;
    using UnityEditor.SceneManagement;
    
    public class CoverageApiTest : MonoBehaviour
    {
        [MenuItem("CodeCoverage/Run Recording")]
        static void RunRecording()
        {
            CodeCoverage.VerbosityLevel = LogVerbosityLevel.Verbose;
    
            int i;
    
            EditorSceneManager.OpenScene("Assets/Scenes/Scene1.unity");
    
            CodeCoverage.StartRecording();
    
            for (i = 0; i < 1000; ++i)
            {
                Instantiate(Resources.Load("ComplexPrefab1"));
            }
    
            CodeCoverage.PauseRecording();
    
            EditorSceneManager.OpenScene("Assets/Scenes/Scene2.unity");
    
            CodeCoverage.UnpauseRecording();
    
            for (i = 0; i < 1000; ++i)
            {
                Instantiate(Resources.Load("ComplexPrefab2"));
            }
    
            CodeCoverage.StopRecording();
        }
    }

    Properties

    VerbosityLevel

    Sets the verbosity level used in editor and console logs. The default level is Info.

    Declaration
    public static LogVerbosityLevel VerbosityLevel { get; set; }
    Property Value
    Type Description
    LogVerbosityLevel

    The verbosity level used in editor and console logs.

    Methods

    PauseRecording()

    Call this to pause the recording on the current coverage recording session.

    Declaration
    public static void PauseRecording()

    StartRecording()

    Call this to start a new coverage recording session.

    Declaration
    public static void StartRecording()

    StopRecording()

    Call this to end the current coverage recording session.

    Declaration
    public static void StopRecording()

    UnpauseRecording()

    Call this to continue recording on the current coverage recording session, after having paused the recording.

    Declaration
    public static void UnpauseRecording()
    In This Article
    • Properties
      • VerbosityLevel
    • Methods
      • PauseRecording()
      • StartRecording()
      • StopRecording()
      • UnpauseRecording()
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023