简体   繁体   English

将单元测试映射到方法

[英]Mapping Unit Tests to methods

We're using Microsoft's Unit Test program and we use the Unit Test Wizard to create one-to-one mapping for methods in each class from the business layer. 我们正在使用Microsoft的单元测试程序,并使用单元测试向导为业务层中每个类中的方法创建一对一的映射。 The issue is the amount of work needed go through and determine if we are missing any tests after the initial tests were created. 问题是需要进行大量工作,并确定在创建初始测试后是否缺少任何测试。

Currently I have to run the wizard and look for tests that have a "1" appended to the default name [method][test]. 当前,我必须运行向导并寻找默认名称为[method] [test]附加“ 1”的测试。 Those with that name mean we have already have a test for that method. 具有该名称的用户意味着我们已经对该方法进行了测试。 The ones without an append 1 mean those are methods that don't have a Unit Test that follow the default naming convention. 没有附录1的方法意味着这些方法没有遵循默认命名约定的单元测试。

I'm wondering if there is away to map Unit Test to a method with attribute on the Method so it doesn't take as much work. 我想知道是否存在将单元测试映射到方法上具有属性的方法的麻烦,因此它不需要太多的工作。 And yes, I know if we were following TDD we would write the Unit Test first. 是的,我知道如果我们遵循TDD,我们将首先编写单元测试。 We write the test in parallel to development (but sometimes in rush it is missed). 我们与开发并行地编写测试(但是有时会匆忙地漏掉它)。

If you are using Visual Studio 2012 and have the appropriate version, it has proper code coverage analysis built in: "Run tests with code coverage". 如果您使用的是Visual Studio 2012,并且具有适当的版本,则它将内置适当的代码覆盖率分析:“使用代码覆盖率运行测试”。

Otherwise, you can use a diagnostic tool to run code coverage, such as NCover. 否则,您可以使用诊断工具来运行代码覆盖率,例如NCover。 You can do this from inside Visual Studio using TestDriven.net 您可以使用TestDriven.net在Visual Studio内部进行此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM