docs.unity3d.com
    Show / Hide Table of Contents

    Class Events

    Events invoked during a code coverage session. A code coverage session is the period between starting and finishing capturing code coverage data.

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

    In the following example we create event handler methods which subscribe to the onCoverageSessionStarted, onCoverageSessionFinished, onCoverageSessionPaused and onCoverageSessionUnpaused events. We use the InitializeOnLoad attribute to make sure that they will resubscribe on Domain Reload, when we enter Play Mode for example.

    using UnityEngine;
    using UnityEditor;
    using UnityEditor.TestTools.CodeCoverage;
    
    [InitializeOnLoad]
    public class CoverageSessionListener
    {
        static CoverageSessionListener()
        {
            Events.onCoverageSessionStarted += OnSessionStarted;
            Events.onCoverageSessionFinished += OnSessionFinished;
            Events.onCoverageSessionPaused += OnSessionPaused;
            Events.onCoverageSessionUnpaused += OnSessionUnpaused;
        }
    
        static void OnSessionStarted(SessionEventInfo args)
        {
            Debug.Log($"{args.SessionMode} Code Coverage Session Started");
        }
        static void OnSessionFinished(SessionEventInfo args)
        {
            Debug.Log($"{args.SessionMode} Code Coverage Session Finished");
    
            string paths = string.Empty;
            foreach (string path in args.SessionResultPaths)
                paths = string.Concat(paths, "\n", path);
    
            Debug.Log($"Code Coverage Results were saved in: {paths}");
        }
    
        static void OnSessionPaused(SessionEventInfo args)
        {
            Debug.Log($"{args.SessionMode} Code Coverage Session Paused");
        }
    
        static void OnSessionUnpaused(SessionEventInfo args)
        {
            Debug.Log($"{args.SessionMode} Code Coverage Session Unpaused");
        }
    }

    Events

    onCoverageSessionFinished

    This event is invoked when a code coverage session is finished.

    Declaration
    public static event Action<SessionEventInfo> onCoverageSessionFinished
    Event Type
    Type Description
    Action<SessionEventInfo>

    onCoverageSessionPaused

    This event is invoked when a code coverage session is paused.

    Declaration
    public static event Action<SessionEventInfo> onCoverageSessionPaused
    Event Type
    Type Description
    Action<SessionEventInfo>

    onCoverageSessionStarted

    This event is invoked when a code coverage session is started.

    Declaration
    public static event Action<SessionEventInfo> onCoverageSessionStarted
    Event Type
    Type Description
    Action<SessionEventInfo>

    onCoverageSessionUnpaused

    This event is invoked when a code coverage session is unpaused.

    Declaration
    public static event Action<SessionEventInfo> onCoverageSessionUnpaused
    Event Type
    Type Description
    Action<SessionEventInfo>
    In This Article
    • Events
      • onCoverageSessionFinished
      • onCoverageSessionPaused
      • onCoverageSessionStarted
      • onCoverageSessionUnpaused
    Back to top
    Terms of use
    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