morganpdx
morganpdx

Reputation: 1876

VS2010 and Create Unit Tests... no tests generated

I'm trying to add some unit tests to an existing code base using Visual Studio 2010's unit test generator. However, in some cases when I open a class, right click --> Create Unit Tests..., after I select the methods to generate tests for it will create what is essentially a blank test. Are there situations where this can happen? In every case I select at least one public method to gen tests for, and all it generates is this:

using TxRP.Controllers; //The location of the code to be tested
using Microsoft.VisualStudio.TestTools.UnitTesting;

That's it. Nothing else. Strange, right?

I should note that this is all MVC 2 controller code, and I have been able to gen tests for other controllers with no problem, and all my controllers follow pretty much the same format. No error seems to be thrown, as it gens the empty page happily and adds it to the project as if everything is just fine.

Has anyone had experience with the same type of thing happening, and was there any answer found as to why?

UPDATE: There is in fact an error during generation:

While trying to generate your tests, the following errors occurred:
Value cannot be null.
Parameter name: key

After some research, the only possible solution I found is that this error occurrs if you're trying to generate tests to a test file that already exists. However, this solution is not working for me...

Upvotes: 1

Views: 4614

Answers (3)

Jeff Arms
Jeff Arms

Reputation: 11

This problem is caused by the previously generated test file having been moved to a folder other than the root folder in the test project.

Resolution Move the test file into the test project root folder. Generate the new tests Move the test file back to the folder location you want in the test project.

Upvotes: 1

ioWint
ioWint

Reputation: 1629

I have no clue why they dont call it a BUG! in a typical enterprise level software development it is more than a coincidence where multiple people generate unit tests for different methods of the same class @ different points of time. We always end up with this error and it is not helping us any way! Feels as if the Context Menu "Create Unit Tests" has lil use!

Error description: "While trying to generate your tests, the following errors occurred: Value cannot be null. Parameter name: key "

Upvotes: 0

morganpdx
morganpdx

Reputation: 1876

If you try to generate tests for a class which already has existing tests in another file in the project, it will just generate an empty file as described above. Changing the filename is not sufficient, nor is using a different location within the project. Basically it seems to enforce the one-testfile-per-class convention across the entire project.

Upvotes: 3

Related Questions