Skip to content

VsixTesting allows you to easily test your Visual Studio Extensions.

License

Notifications You must be signed in to change notification settings

yannduran/VsixTesting

 
 

Repository files navigation

VsixTesting

# Join the chat at https://gitter.im/josetr/VsixTesting Build status codecov MyGet

VsixTesting allows you to easily test your Visual Studio Extensions.

Image

Getting Started

The fastest way to get started is cloning the VsixTestingSamples repo and playing with it.

git clone https://github.com/josetr/VsixTestingSamples

Create the test project

TestProject.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="xunit" Version="2.3.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
    <PackageReference Include="VsixTesting.Xunit" Version="0.1.49-beta" /> 
    <!-- Optional package containing types used in this sample. -->    
    <PackageReference Include="VSSDK.Shell.11" Version="11.0.4" /> 
    <!-- 
      <ProjectReference Include="..\MyVsixProject\MyVsixProject.csproj" />      
      * VsixTesting contains an MSBuild target that scans all project references
         and if they generate a .vsix package, it will copy them 
         to the output folder where the test assembly is located.
      * VsixTesting will install all .vsix packages located next to the test assembly.
    -->        
  </ItemGroup>
</Project>

TestClass.cs

using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Xunit;

namespace Tests
{  
    public class TestClass
    {
        [VsFact]
        void FactTest()
            =>  Assert.NotNull(Package.GetGlobalService(typeof(SVsWebBrowsingService)));

        [VsTheory]
        [InlineData(123)]
        void TheoryTest(int n)
        {
            Assert.NotNull(Package.GetGlobalService(typeof(SVsWebBrowsingService)));
            Assert.Equal(123, n);
        }
    }
}

Configuring how tests run

All the settings are located in ITestSettings and are implemented by 3 attributes:

  • [VsTestSettings] for classes/collections/assemblies
  • [VsFact] and [VsTheory] for methods

Intellisense should be used to read the documentation for each property that can be set.

License

This repository is licensed with the Apache, Version 2.0 license.

About

VsixTesting allows you to easily test your Visual Studio Extensions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.5%
  • Smalltalk 0.5%