1

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?

Community
  • 1
  • 1
Denise Skidmore
  • 2,286
  • 22
  • 51

1 Answers1

0

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.

Denise Skidmore
  • 2,286
  • 22
  • 51
Tacoman667
  • 1,391
  • 9
  • 16
  • No, this project is not supposed to be a test project, it is a class library I wish to test. Project properties, Application, Output type is `Class Library`. – Denise Skidmore Jun 18 '14 at 21:40
  • Killing the project and starting over seems to work, but it does not solve the mystery of why. – Denise Skidmore Jun 18 '14 at 21:51
  • Might be it: `{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}` – Denise Skidmore Jun 18 '14 at 21:54
  • Very possible. Somehow those id's weren't properly applied. Those Ids are how VS knows what context menus and tooling to use. – Tacoman667 Jun 18 '14 at 21:58
  • That first GUID matches one in a test project I've just created here. Googling for it brings up several results about test projects, including http://stackoverflow.com/questions/7009943/how-does-visual-studio-mstest-identify-test-projects – ClickRick Jun 18 '14 at 22:22
  • I'll accept the answer for being on the right track even though the question was misunderstood and I think the answer could have been better documented. – Denise Skidmore Jun 19 '14 at 02:10