Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 Unit Testing: Controller must have testable element property set up

I'm trying to use Visual Studio's unit test generation feature. The first thing I found was this extension, but for some reason it doesn't work - even after rebooting, though I can verify the extension is installed, "Generate Unit Test" doesn't show up in the context menu when I right-click within a method.

The next thing I tried was a workaround I found in one of the reviews - apparently the original feature still exists, just buried. The workaround is:

  • Tools->Options
  • Environment->Keyboard
  • Show commands containing 'unit'
  • Attach a shortcut to "EditorContextMenus.CodeWindow.CreateUnitTests".

But that didn't work, either - as in, nothing seems to happen. There are two other commands that may be relevant - EditorContextMenus.CodeWindow.GenerateUnitTests and Project.AddUnitTest. Neither of those work either - the latter just does nothing, the former gives me the error "Controller must have testable element property set up".

So... I'm not really sure what else to try.

like image 513
linkhyrule5 Avatar asked Aug 14 '13 08:08

linkhyrule5


Video Answer


1 Answers

I have a same problem, and here is reason why the error occurred.

In the documentation of code generator, the arthor metions an super important pre-requisite.

In the final release we require a public class and at least one public method, before the Generate Unit Test feature lights up.

http://blogs.msdn.com/b/willy-peter_schaub/archive/2013/07/19/exploring-the-unit-test-generator-vs-extension-v1-rc.aspx

From the article, I have found that there is two requirements make the Code Generator works.

  1. The class must be public
  2. At least one public method in the class

You can try to make the Access modifiers to Public to solve the problem

like image 110
Philip Ding Avatar answered Oct 20 '22 06:10

Philip Ding