Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add additional Test projects to the "Create Unit Tests" context menu in Visual Studio 2015?

How can I add existing Test projects to the right click context menu for "Creating unit tests" in Visual Studio 2015?

It only shows one of the test projects (the project was created using the right click context action). The other project was created using the new project wizard and is not shown.

Missing Projects Available Unit Test Projects

Is there a way to add existing unit test projects to the dropdown list?

like image 823
Silthus Avatar asked Jul 19 '16 09:07

Silthus


People also ask

What context menu option will generate a unit test case?

The Create Unit Tests command creates unit test method stubs. This feature allows easy configuration of a test project, the test class, and the test method stub within it. The Create Unit Tests menu command is only available for C# code.


1 Answers

I have not pinned down which step-s are mandatory, but below are the steps which allowed me to add an existing project to the Intellitest "Create Unit Test" list :

  • Reference Microsoft.Pex.Framework assembly
  • Add "PexAssemblyInfo.cs" file in Properties project's special folder. Edit accordingly.
  • In .csproj file, add <TestProjectType>"UnitTest"</TestProjectType> tag, in <PropertyGroup> node
  • In .csproj file, add <IsCodedUITest>False</IsCodedUITest> tag, in <PropertyGroup> node (probably not required)
  • In .csproj file, add "{3AC096D0-A1C2-E12C-1390-A8335801FDAB}" (Test project type) to <ProjectTypeGuids> tag

Edit: Sample PexAssemblyInfo.cs content

using Microsoft.Pex.Framework.Coverage;
using Microsoft.Pex.Framework.Creatable;
using Microsoft.Pex.Framework.Instrumentation;
using Microsoft.Pex.Framework.Settings;
using Microsoft.Pex.Framework.Validation;

// Microsoft.Pex.Framework.Settings
[assembly: PexAssemblySettings(TestFramework = "xunit-2.0")]

// Microsoft.Pex.Framework.Instrumentation
[assembly: PexAssemblyUnderTest("{YOUR-PROJECT-NAME}")]
[assembly: PexInstrumentAssembly("System.Runtime.Extensions")]
[assembly: PexInstrumentAssembly("System.Linq.Expressions")]
[assembly: PexInstrumentAssembly("System.Threading")]
[assembly: PexInstrumentAssembly("System.Reflection.Extensions")]
[assembly: PexInstrumentAssembly("System.Reflection")]
[assembly: PexInstrumentAssembly("System.Diagnostics.Debug")]
[assembly: PexInstrumentAssembly("System.Runtime")]
[assembly: PexInstrumentAssembly("System.Threading.Tasks")]
[assembly: PexInstrumentAssembly("System.Collections")]

// Microsoft.Pex.Framework.Creatable
[assembly: PexCreatableFactoryForDelegates]

// Microsoft.Pex.Framework.Validation
[assembly: PexAllowedContractRequiresFailureAtTypeUnderTestSurface]
[assembly: PexAllowedXmlDocumentedException]

// Microsoft.Pex.Framework.Coverage
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Runtime.Extensions")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Linq.Expressions")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Threading")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Reflection.Extensions")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Reflection")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Diagnostics.Debug")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Runtime")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Threading.Tasks")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Collections")]
like image 55
Alexis Avatar answered Oct 16 '22 15:10

Alexis