【问题标题】:Why am I missing the "Create Unit Tests..." context menu item in VS 2013?为什么我在 VS 2013 中缺少“创建单元测试...”上下文菜单项?
【发布时间】:2014-06-19 19:02:11
【问题描述】:

我正在尝试在我的 MVC Web API ASP.NET 项目中实现一些单元测试。

我正在使用 VS 2013(终极版,更新 2),并且想使用最小起订量。

我在解决方案中创建了一个测试项目。

跟随this blog post,我想我应该可以在这里右键单击“GetCountOfPlatypusItemRecords”:

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();
    }
    . . .

...并查看“创建单元测试...”菜单项;但我没有(在“组织使用”之后,我看到“生成序列图”,而不是“创建单元测试......”)。为什么我无法使用“创建单元测试...”?

注意:我在主项目和测试项目中都引用了Moq和nunit.framework,并添加了相应的“使用NUnit.Framework”和“使用Moq”

【问题讨论】:

    标签: c# unit-testing visual-studio-2013 nunit moq


    【解决方案1】:

    从外观上看,单元测试生成器不再是 VS 2013 的一部分。不过请查看 this extension,它显然复制了其中的一些功能。

    话虽如此,我还是建议您不要生成单元测试。大多数时候,有意义的测试是您真正必须考虑测试内容的类型,而 IMO 生成器会引导您朝错误的方向前进。另外,我应该指出,Moq 独立于测试框架和您编写测试的方式,因此您实际上并不需要生成测试来尝试 Moq。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      • 2015-09-19
      • 2017-05-13
      • 1970-01-01
      相关资源
      最近更新 更多