Microsoft.VisualStudio.Sdk.TestFramework
17.11.8
Prefix Reserved
dotnet add package Microsoft.VisualStudio.Sdk.TestFramework --version 17.11.8
NuGet\Install-Package Microsoft.VisualStudio.Sdk.TestFramework -Version 17.11.8
<PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework" Version="17.11.8" />
paket add Microsoft.VisualStudio.Sdk.TestFramework --version 17.11.8
#r "nuget: Microsoft.VisualStudio.Sdk.TestFramework, 17.11.8"
// Install Microsoft.VisualStudio.Sdk.TestFramework as a Cake Addin #addin nuget:?package=Microsoft.VisualStudio.Sdk.TestFramework&version=17.11.8 // Install Microsoft.VisualStudio.Sdk.TestFramework as a Cake Tool #tool nuget:?package=Microsoft.VisualStudio.Sdk.TestFramework&version=17.11.8
Microsoft.VisualStudio.Sdk.TestFramework
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.
Install the NuGet package Microsoft.VisualStudio.Sdk.TestFramework, or for Xunit test projects, install the more specific Microsoft.VisualStudio.Sdk.TestFramework.Xunit package
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>
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 theMockVsActivityLog
type, then setting theForwardTo
property.OLE.Interop.IServiceProvider
SVsTaskSchedulerService
SVsUIThreadInvokerPrivate
More may be added and can be found in source code.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net8.0-windows8.0 is compatible. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.2
- Microsoft.ServiceHub.Framework.Testing (>= 4.4.22)
- Microsoft.VisualStudio.Composition (>= 17.11.9)
- Microsoft.VisualStudio.Interop (>= 17.11.39607)
- Microsoft.VisualStudio.SDK.Analyzers (>= 17.7.41)
- Microsoft.VisualStudio.Shell.15.0 (>= 17.11.39607)
- Microsoft.VisualStudio.Utilities (>= 17.11.39607)
- System.ComponentModel.Composition (>= 8.0.0)
-
net8.0
- Microsoft.ServiceHub.Framework.Testing (>= 4.4.22)
- Microsoft.VisualStudio.Composition (>= 17.11.9)
- Microsoft.VisualStudio.Interop (>= 17.11.39607)
- Microsoft.VisualStudio.Utilities (>= 17.11.39607)
- System.ComponentModel.Composition (>= 8.0.0)
-
net8.0-windows8.0
- Microsoft.ServiceHub.Framework.Testing (>= 4.4.22)
- Microsoft.VisualStudio.Composition (>= 17.11.9)
- Microsoft.VisualStudio.Interop (>= 17.11.39607)
- Microsoft.VisualStudio.SDK.Analyzers (>= 17.7.41)
- Microsoft.VisualStudio.Shell.15.0 (>= 17.11.39607)
- Microsoft.VisualStudio.Utilities (>= 17.11.39607)
- System.ComponentModel.Composition (>= 8.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Microsoft.VisualStudio.Sdk.TestFramework:
Package | Downloads |
---|---|
Microsoft.VisualStudio.Sdk.TestFramework.Xunit
A test library to help in writing unit and integration tests for Visual Studio extensions. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Microsoft.VisualStudio.Sdk.TestFramework:
Repository | Stars |
---|---|
rubicon-oss/LicenseHeaderManager
Manage license headers for your source code files in Visual Studio
|
Version | Downloads | Last updated |
---|---|---|
17.11.8 | 167 | 10/26/2024 |
17.6.16 | 69,519 | 7/10/2023 |
17.2.7 | 21,437 | 6/21/2022 |
17.2.5 | 786 | 5/25/2022 |
17.1.3-alpha | 299 | 1/13/2022 |
17.0.15 | 4,915 | 11/19/2021 |
16.5.22-beta | 7,925 | 10/27/2020 |