Loupe - Log - Monitor - Resolve
Loupe / Developer's Guide / For .NET Core / 6 / 8 / Using Loupe with Unit Testing / Getting Started - Unit Testing with NUnit
In This Topic
    Getting Started - Unit Testing with NUnit
    In This Topic

    To effectively unit test assemblies that have Loupe integrated with NUnit you'll want to set up a special SetUpFixture class to handle configuring, starting, and stopping the Loupe Agent.  You can use the sample below and modify the product name to fit your scenario. 

    NUnit Set Up Fixture Class Example
    Copy Code
    using Gibraltar.Agent;
    using NUnit.Framework;
    
    namespace NUnitTestSample
    {
        /// 
        /// Our initialization class - used at the start and end of all unit tests
        ///
        [SetUpFixture]
        public class SetUpFixture
        {
            /// 
            /// Our one-time initialization method called at the very start of running unit tests in this assembly
            ///
            [SetUp]
            public static void Initialize()
            {
                Log.Initializing += OnLogInitializing;
                Log.StartSession("Starting unit tests");
            }
    
            private static void OnLogInitializing(object sender, LogInitializingEventArgs e)
            {
                e.Configuration.Publisher.ProductName = "Your Product";
                e.Configuration.Publisher.ApplicationName = "Unit Tests";
                e.Configuration.Publisher.ApplicationType = ApplicationType.Console;
            }
    
            /// 
            /// Our one-time cleanup method called at the very end of running unit tests in this assembly
            ///
            [TearDown]
            public static void Cleanup()
            {
                Log.EndSession("Unit tests ending");
            }
        }
    } 
    
    See Also