Class UnityErrorLogInterceptor
Class used to replicate the Unity test runner behaviour of failing tests when either UnityEngine.Debug.LogError(System.Object) or UnityEngine.Debug.LogException(System.Exception) is called.
Implements
Namespace: Responsible.Unity
Assembly: Responsible.dll
Syntax
public class UnityErrorLogInterceptor : IExternalResultSource
Methods
ExpectLog(LogType, Regex)
Expect a log message during execution of any subsequent test instructions. Similar to UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType,System.Text.RegularExpressions.Regex), but needs to be called instead of that, in order to work when executing test instructions.
Declaration
public void ExpectLog(LogType logType, Regex regex)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.LogType | logType | Log type to expect. |
Regex | regex | Regex to match the message to be expected. |
Remarks
Will call UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType,System.Text.RegularExpressions.Regex), so it doesn't need to be called separately.
GetExternalResult<T>(CancellationToken)
Intercept errors, respecting and not toggling the globally mutable UnityEngine.TestTools.LogAssert.ignoreFailingMessages. Will complete with an error if either an error or exception is logged, and will never complete if neither of those happens.
Declaration
public Task<T> GetExternalResult<T>(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Token used to cancel this operation. |
Returns
Type | Description |
---|---|
Task<T> | Task, which will complete with an error if either an error or exception is logged. |
Type Parameters
Name | Description |
---|---|
T | Type of the test operation being run. |