Class CodeCoverage | Code Coverage | 0.2.3-preview
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, initialises a number of instances of a prefab, then pauses the recording to load another scene, unpauses the recording, initialises a number of instances of a different prefab and finally stops the recording.

    using UnityEngine;
    using UnityEditor;
    using UnityEditor.TestTools.CodeCoverage;
    using UnityEditor.SceneManagement;
    
    public class CoverageApiTest : MonoBehaviour
    {
        [MenuItem("CodeCoverage/Run Recording")]
        static void RunRecording()
        {
            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();
        }
    }

    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
    • 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