How to handle abort from a Test Step?

In scenario 2, sometimes my lengthy operations take place in an isolated class that does not reference OpenTAP, so the isolated class can’t call OpenTap.TapThread.ThrowIfAborted().

There’s an easy solution, just pass in PlanRun.MainThread.AbortToken to the isolated class. This works fine since PlanRun.MainThread.AbortToken is a CancellationToken, a common .NET type. Then the isolated class can call cancelToken.ThrowIfCancellationRequested(), so it will stop execution if the user has requested an abort.

4 Likes