简体   繁体   中英

How does Visual Studio 2010 determine which projects are test projects?

I have a project made recently by a team member. I added some classes and wanted to unit test them. I added the project to our unit test solution, but I can't right-click on any function and select "Create Unit Test". I found a solution to manually type EditorContextMenus.CodeWindow.CreateUnitTests in the command window, but then I get an error "Test generation is only supported on non test projects."

I searched for "test" through the whole project and only came up with PopulateStructure so there's no functions with test attributes. I deleted a stray reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework which the team member said had been automatically inserted by Visual Studio. The reference did not come back when I compiled, but I still couldn't auto generate tests.

I searched for [ and the only attribute outside AssemblyInfo.cs is one of our own:

[AttributeUsage(AttributeTargets.All)]
public class OurAttribute_C : System.Attribute
{
    ...

I did a diff between this project file and another project file I'm testing, and saw nothing obvious. Same with the AssemblyInfo files.

I know I can manually create the tests without the tool, but why does VS2010 think that this project is a unit test project?

In searching for this I found a lot of complaints about the feature being entirely missing from VS2012 beta, I have the feature in other projects just not this one. A couple places had related complaints, but no answers.

Similar (slightly different) question with no answer: Unit test generation error in Visual studio website project?

When you created the "test" project, did you choose a testing project type?

In the csproj, There is a tag called ProjectTypeGuids that gives the project a type or list of types for the IDE to understand what IDE tooling to use. You can edit it manually in the csproj.

Here is a non-definitive list of GUIDS

Easiest thing would be to just kill that project and create a new project from the correct template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM