Git Product home page Git Product logo

Comments (3)

maysonchen-cs avatar maysonchen-cs commented on May 18, 2024 1

Follow https://github.com/microsoft/vssdktestfx/blob/main/doc/mstest.md, I successfully run all my cases with NUnit.
We may not really need to add separate attribute class. Manually adding AssemblySetup.MockServiceProvider.Reset() to the constructor or [SetUp] section of every test class should also work.

Add this class to your test folder.

using Microsoft.VisualStudio.Sdk.TestFramework;
using NUnit.Framework;

namespace Application.Test
{
    [SetUpFixture]
    public class AssemblySetup
    {
        internal static GlobalServiceProvider MockServiceProvider { get; private set; }

        [OneTimeSetUp]
        public void RunBeforeAnyTests()
        {
            MockServiceProvider = new GlobalServiceProvider();
        }

        [OneTimeTearDown]
        public void RunAfterAnyTests()
        {
            MockServiceProvider.Dispose();
        }

    }
}

Create a attribute class

using System;
namespace Application.Test
{
    [AttributeUsage(AttributeTargets.Class)]
    public class TestWithAttribute : Attribute
    {
        public TestWithUnityContainerAttribute()
        {
            AssemblySetup.MockServiceProvider.Reset();
        }
    }
}

Add the attribute annotation to every test class

namespace Application
{
    [TestFixture]
    [TestWithAttribute]
    public class AnalysisTest 
    {
       [Test]
        public void Test()
        {
            Assert.AreEqual(1, 1);
        }
    }
}

from vssdktestfx.

AArnott avatar AArnott commented on May 18, 2024

Not directly. But it doesn't directly support MSTest either and folks get by just fine with it. We only added Xunit-specific helpers very recently. Just review either xunit or mstest documentation and do the equivalent thing for NUnit. Once you figure it out, if you'd like to share back, I'd entertain a PR to add NUnit to our docs.

from vssdktestfx.

AArnott avatar AArnott commented on May 18, 2024

Thank you for sharing. Wanna send a PR that adds an nunit.md doc to the repo, @maysonchen-cs?

from vssdktestfx.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.