MetalamaConceptual documentationCreating aspectsTesting and debugging aspectsTesting run-time behavior
Open sandboxFocusImprove this doc

Unit testing aspects at run time

(TODO: This article is currently in draft form.)

The objective of this approach is to apply an aspect to a specific target code, then create standard unit tests to verify that the resulting code behaves as expected.

For example, to test a logging aspect, you could configure your logging aspect to log to an in-memory StringWriter. Then, use a standard unit test to confirm that a logged method, when invoked from the test method, yields the expected result in the StringWriter. This concept is illustrated in the code snippet below.

class MyTests
    StringWriter _logger = new();

    public void TestVoidMethod()

        Assert.Equal( @"
Entering VoidMethod(5).
VoidMethod(5) succeeded.

    private void VoidMethod(int p)