Metalama / / Conceptual documentation / Creating aspects / Testing and debugging aspects / Testing run-time behavior
Open sandbox

Unit testing aspects at run time

(This article is just a sketch.)

This approach aims to apply the aspect to some target code and create regular unit tests that verify that the resulting code has the desired behavior.

For instance, if you want to test a logging aspect, you can make your logging aspect log to an in-memory StringWriter and use a standard unit test to verify that some logged method, when called from the test method, produces the expected result in the StringWriter. This idea is drafted in the following code snippet.

class MyTests
    StringWriter _logger = new();

    public void TestVoidMethod()

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



    private void VoidMethod( int p )