Skip to content

A testing framework for Visual Studio extensions

License

Notifications You must be signed in to change notification settings

Vino-Wang/vssdktestfx

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 NuGet 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
  • 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.

About

A testing framework for Visual Studio extensions

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 58.5%
  • PowerShell 40.4%
  • Other 1.1%