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

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.

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.
The class must be public
At least one public method in the class
You can try to make the Access modifiers to Public to solve the problem

Apparently the extension doesn't work for structs, I found out today - no matter what you do, you get the "Controller must have have testable element property set up" error.

Related

Can JS-DOM test code that uses Tailwind's peer / peer-invalid mechanism?

Tailwind offers a feature where you can give an input element the peer class and then, in a sibling element use the peer-invalid: pseudoclass to apply conditional stylings. This is commonly used to provide helper text when a form field is not valid.
I don't see how this can be tested in JS-DOM though, as JS-DOM doesn't have access to the actual CSS when it is just rendering components in unit tests.
The information I have seen about getting JS-DOM to use CSS at all is kinda sketchy, so I was wondering if it's even worth trying to get it to evaluate a bunch of tailwind classes in a NextJS/Jest/RTL project. I'm using Tailwind 3 so it's not even like I have a big file full of generated classes I could try and pass to JS-DOM :/
So can it be done? (Note the hard fact please mods!!!)
(And, somewhat more subjectively, should it be done? Or is there a better way to approach this?)

When TestClass Name & Namespace length reaches 128 characters, the test class shows as 'Excluded' in Test Explorer when PostSharp is referenced

I recently created a VS2015 solution to migrate projects & test projects from VS2010. I am experiencing odd behaviour with one particular test class which has a reference to PostSharp, where the combined namespace and test class name reaches 128 characters (which isn't many in my opinion). The tests show as 'excluded' in the test explorer window (When the tests are grouped by project). Also when I right click within the test class, the output window shows 'No tests found to run'.
When I try to select the test methods within the 'external' node, the following test is displayed: 'Source: no source available'.
I have tried creating another test project in a different solution, and purposely exceeded the 128 characters without postsharp and the problem goes away.
The obvious fix for this is to shorten the length of the namespace, however I am curious as to whether anyone has ever found a reason / solution for this?

Unit test says function was called, but console.logs are not showing up

I have a function inside another function that is supposedly getting called, according to my expect(Parse.User.Login).toHaveBeenCalled() line, but there are some console statements inside the callback to that which aren't showing up.
Is there some type of dependency I'm missing on my unit test causing the callback not to have called? I think it is getting to the server, because it tells me I need a Parse.initialize with the application keys if that's not present.
How do I resolve it?
It just occurred to me, maybe that's something in Parse.js telling me I need the Parse.initialize(keys,keys). I changed the parse keys to nonsense, and its not telling me they're wrong, so it must be that parse isn't being touched at all. No request is being sent to the server.
I've been putting up a few questions about this, but now I guess this can't be done with Karma-jasmine -- at least the way the app is set up right now. It's depending on a web service to give the errors, instead of having an angular directive set up up front to detect the errors in the fields beforehand.
I'm a newbie at this obviously, or I would have recognized this sooner:
This type of testing, where you are depending on responses from the server and that's that, should be delegated to E2E tests.
Meaning, here what am I supposed to test that wouldn't be just hardcoding the desired response right into the jasmine Spy? What would that do to just set the rootScope to a user attribute? Maybe, if state.go changed the view to another page, and then acted on the $rootScope data, this would make sense. But for now, there's no point. I'm not designing the next step, nor do I know what it is at the moment, so I can only sit back.

VS2013 Express Test Explorer - how to expand all categories?

I'd like to view the tests in Test Explorer by class, but when I do so, even the ones that failed get hidden under the class categories, so I have to manually expand them all. I wind up just viewing them by status (pass/fail), but then they get all mushed together in one big long list. Is there any way to expand all the categories at once?
Not possible unfortunately . You have to manually go and check them. But the test view by resharper gives a better overview.
Here you can see all the failed tests by number. Clicking on the failed tests tab(#67) on top will show just the failed tests (project-wise in this scenario) :

AntiForgeryToken HtmlHelper throwing NotImplementedException when run within a RazorGenerator class

I'm using RazorGenerator to unit test my Razor/MVC3 per David Ebbo's post here http://blog.davidebbo.com/2011/06/unit-test-your-mvc-views-using-razor.html and every time I attempt to use the AntiForgeryToken HtmlHelper (with no method arguments), it throws a NotImplementedException. What gives? As best I can tell, both my cshtml file and the view.generated.cs the correct method in System.Web.Mvc.dll, in the System.Web.Mvc namespace's HtmlHelper class. I've downloaded the latest source for the RazorGenerator project and don't see the word "forgery" contained within it anywhere, so I don't think I'm getting confused about exactly which HtmlHelper.AntiForgeryToken() method I'm hitting.
The code sample of my unit test follows:
[Test]
public void Index_RendersView()
{
var view = new Index();
// For test to succeed, this should not throw exception
view.RenderAsHtml();
}
Pretty basic. I'll spend some time digging under the hood to figure this one out and will follow up here if I figure this one out, but in the meantime I'm wondering if anyone else has encountered this and already worked out a solution.
I corresponded with David Ebbe, one of the (or, the) project owners on CodePlex, and he altered something within the RazorGenerator project source to fix this. Remarkably, he had it fixed within less than 1/2 hour of me asking the question on the CodePlex board.
I'm going to vote to have this question deleted since I don't think there's any value to keeping it around this site.