dotMemory Unit 2.1 Help

Simple Scenarios. AssertTraffic Attribute

For simple assertions about traffic, you can use the AssertTraffic attribute. It allows you to assert that a test allocates less than a specific number of objects or memory amount.
The main limitation of such an approach is that traffic is calculated for the entire unit test and only for allocated objects. Thus, if you want to check traffic on a specific time interval or make assertions about collected objects, you should use the Traffic type.


// Assert the test allocates no more than 1000 strings [AssertTraffic(AllocatedObjectsCount = 1000, Types = new[] {typeof(string)})] [Test] public void TestMethod1() { ... }

AssertTraffic Properties

AllocatedSizeInBytes long Asserts the size of allocated objects in bytes.
AllocatedObjectsCount int Asserts the number of allocated objects.
Types Type[] Selects objects for assertions by type.
Interfaces Type[] Selects objects for assertions by implemented interface.
Namespaces string[] Selects objects for assertions by namespace *.
The asterisk (*) wildcard is supported.
Last modified: 7 March 2016