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()
    Back to top Copyright © 2022 Unity Technologies
    Generated by DocFX
    on Tuesday, November 22, 2022
    Terms of use