コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】Unity Test Runner の開始終了を検知する方法

概要

using UnityEditor;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;

[InitializeOnLoad]
internal sealed class Example : ICallbacks
{
    static Example()
    {
        var api = ScriptableObject.CreateInstance<TestRunnerApi>();
        api.RegisterCallbacks( new Example() );
    }
    
    public void TestStarted( ITestAdaptor test )
    {
        Debug.Log( "テスト開始:" + test.Name );
    }

    public void RunStarted( ITestAdaptor testsToRun )
    {
        Debug.Log( "実行開始:" + testsToRun.Name );
    }

    public void RunFinished( ITestResultAdaptor result )
    {
        Debug.Log( "実行終了:" + result.Name );
    }

    public void TestFinished( ITestResultAdaptor result )
    {
        Debug.Log( "テスト終了:" + result.Name );
    }
}

参考サイト様