Coder Social home page Coder Social logo

isabella232 / vssdktestfx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/vssdktestfx

0.0 0.0 0.0 951 KB

A testing framework for Visual Studio extensions

License: MIT License

C# 63.56% PowerShell 35.40% Batchfile 0.46% Dockerfile 0.58%

vssdktestfx's Introduction

Visual Studio SDK Test Framework

NuGet package Build Status Join the chat at https://gitter.im/Microsoft/extendvs

The VS SDK Test Framework is a library for your unit tests that exercise VS code to use so that certain core VS functionality works outside the VS process so your unit tests can function. For example, ThreadHelper and obtaining global services from the static ServiceProvider tend to fail in unit tests without this library installed.

Consuming this test framework

Microsoft Internal users: See specific guidance if consuming within the VS repo.

  1. Install the NuGet package Microsoft.VisualStudio.Sdk.TestFramework, or for Xunit test projects, install the more specific Microsoft.VisualStudio.Sdk.TestFramework.Xunit package

  2. Make sure your unit test project generates the required binding redirects by adding these two properties to your project file:

    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
  3. Apply some changes to your test project source as appropriate given the test framework you're already using:

Main Thread considerations

This library will create a mocked up UI thread, such that ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync() can switch to it. Your unit tests do not start on this mocked up UI thread. If your product code contains checks that it is invoked on the UI thread (e.g. ThreadHelper.ThrowIfNotOnUIThread()) your test method should look like this:

[TestMethod] // or [Fact]
public async Task VerifyWeDoSomethingGood()
{
    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
    MyVSPackage.DoSomethingAwesome();
}

Built in service mocks

There are a collection of "base services" that the VSSDKTestFx comes with mocks for. Calling GlobalServiceProvider.AddService for any of these will result in an InvalidOperationException being thrown claiming that the service is already added.

These services include:

  • SVsActivityLog Customize behavior by acquiring the service and downcasting to the MockVsActivityLog type, then setting the ForwardTo property.
  • OLE.Interop.IServiceProvider
  • SVsTaskSchedulerService
  • SVsUIThreadInvokerPrivate

More may be added and can be found in source code.

Contributing

This project has adopted the Microsoft Open Source Code of Conduct.

See our contributing doc for more info.

vssdktestfx's People

Contributors

aarnott avatar amadeusw avatar crmann1 avatar dependabot[bot] avatar eilon avatar jpwilli avatar juchom avatar newrad0603 avatar reduckted avatar srdjanjovcic avatar stevebush avatar xuachen avatar

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.