Simple Cases. 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.
You can add any number of AssertTraffic
attributes in case you want to filter traffic by a number of conditions.
// Assert the test allocates no more than 1000 strings
[AssertTraffic(AllocatedObjectsCount = 1000, Types = new[] {typeof(string)})]
[Test]
public void TestMethod1()
{
...
}
note
* Note that your code can generate objects of system types, like
string
,int
, and so on. All such objects belong toSystem
namespaces.
Name | Type | Description |
---|---|---|
|
| Asserts the size of allocated objects in bytes. |
|
| Asserts the number of allocated objects. |
|
| Selects objects for assertions by type. |
|
| Selects objects for assertions by implemented interface. |
|
| Selects objects for assertions by namespace *. The asterisk (*) wildcard is supported. |