问题描述:

I'm trying to implement some Unit Testing in my MVC Web API ASP.NET project.

I am using VS 2013 (Ultimate, Update 2), and want to use Moq.

I have created a Test project within the solution.

In following along with this blog post, I'm thinking that I should be able to right-click on "GetCountOfPlatypusItemRecords" here:

public class PlatypusItemsController : ApiController

{

private readonly IPlatypusItemRepository _PlatypusItemRepository;

public PlatypusItemsController(IPlatypusItemRepository PlatypusItemRepository)

{

if (PlatypusItemRepository == null)

{

throw new ArgumentNullException("PlatypusItemRepository");

}

_PlatypusItemRepository = PlatypusItemRepository;

}

[Route("api/PlatypusItems/Count")]

public int GetCountOfPlatypusItemRecords()

{

return _PlatypusItemRepository.GetCount();

}

. . .

...and see a "Create Unit Tests..." menu item; but I don't (after "Organize Usings," I see "Generate Sequence Diagram," not "Create Unit Tests..."). Why is "Create Unit Tests..." not available for me?

Note: I am referencing Moq and nunit.framework in both the main project and the test project, and added the corresponding "using NUnit.Framework" and "using Moq"

网友答案:

From the looks of it, the Unit Test Generator is no longer a part of VS 2013. Check out this extension though, which apparently replicates some of those features.

Having said that, I'd advise against generating your unit tests. Most of the time, meaningful tests are the kind where you really have to think through what you are testing, and IMO the generator guides you in the wrong direction. Also, I should point out that Moq is independent of both the testing framework and the way you've written your tests, so you don't really need to generate the tests in order to try out Moq.

相关阅读:
Top