dotMemory Unit 3.2 Help

Work with Unsupported Unit Testing Frameworks

If the unit testing framework you use is not supported by dotMemory Unit out of the box (see the list of supported frameworks), you can provide support using the DotMemoryUnitController class.

All you need to do is to tell dotMemory Unit where your test method starts and where it ends. This is done by means of two methods: DotMemoryUnitController.TestStart() and DotMemoryUnitController.TestEnd(). We recommend that you create an IDisposable class* that uses these methods and then wrap the code in your tests with the using statement that creates an instance of this class.

Example

internal class dotMemoryUnit : IDisposable { [MethodImpl(MethodImplOptions.NoInlining)] private dotMemoryUnit() { // frame1 is DotMemoryUnit.Support() method; frame2 is "test" method DotMemoryUnitController.TestStart(new StackTrace().GetFrame(2).GetMethod()); } [MethodImpl(MethodImplOptions.NoInlining)] public static IDisposable Support() { return new dotMemoryUnit(); } public void Dispose() { DotMemoryUnitController.TestEnd(); } } public class Tests { [SomeTestAttribute] // an attribute that specifies a test in the framework of your choice public void TestMethod1() { using (dotMemoryUnit.Support()) { ... // your code goes here } } }

DotMemoryUnitController static class

Allows providing dotMemory Unit with support for any unit testing framework.

QueryBuilder methods

Name

Description

TestStart(MethodBase testMethod)

Indicates the start of a test. testMethod specifies test method that uses dotMemory Unit. See example above.

TestEnd()

Indicates the end of a test. Make sure this method is always called (even if a test throws an exception).

TestFailed(bool onMemoryAssert)

Indicates test failure. Call this method when handling an exception in your test. Use onMemoryAssert to indicate whether the test failed on "memory" assertion or due to another reason. By default, onMemoryAssert is true.

Usage of this method is required only if you use snapshot saving strategies.

IMPORTANT! dotMemory.Check calls TestFailed(true) by itself on assertion fails.

Last modified: 10 May 2022