mercredi 7 avril 2021

Cannot Console.WriteLine in NUnit OneTimeSetUp and OneTimeTearDown under SetUpFixure

I just created a very simple NUnit test project in Visual Studio (.NET Core 3.1) as following. However, after I run the test and open the additional output for the result in Visual Studio, it only contains "Running test", without "Initialize" and "Teardown". How could this happen?

using NUnit.Framework;
using System;

namespace TestProject1
{
    [SetUpFixture]
    public class MySetUpClass
    {
        [OneTimeSetUp]
        public void RunBeforeAnyTests()
        {
            Console.WriteLine("Initialize");
        }

        [OneTimeTearDown]
        public void RunAfterAnyTests()
        {
            Console.WriteLine("Teardown");
        }
    }

    [TestFixture]
    public class Tests
    {
        [Test]
        public void Test1()
        {
            Console.WriteLine("Running test");
            Assert.Pass();
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire