How can I execute Code Coverage Analysis on my unit tests automatically each time I execute a build process from my development machine?
每次从开发机器执行构建过程时,如何自动对单元测试执行代码覆盖率分析?
I have searched the internet but I have not found any related questions or posts.
我搜索了互联网,但我没有找到任何相关的问题或帖子。
2 个解决方案
#1
According to info from MSDN:
根据MSDN的信息:
-
In Team Explorer, open Builds, and then add or edit a build definition.
在团队资源管理器中,打开“构建”,然后添加或编辑构建定义。
-
On the Process page, expand Automated Tests, Test Source, Run Settings. Set Type of Run Settings File to Code Coverage Enabled.
在“处理”页面上,展开“自动测试”,“测试源”,“运行设置”。将“运行设置文件的类型”设置为“已启用代码覆盖率”。
If you have more than one Test Source definition, repeat this step for each one.
如果您有多个测试源定义,请对每个测试源重复此步骤。
-
But there is no field named Type of Run Settings File.
但是没有名为“运行设置文件类型”的字段。
Under Automated Tests, select Test Assembly and choose the ellipsis button [...] at the end of the line. In the Add/Edit Test Run dialog box, under Test Runner, choose Visual Studio Test Runner.
在Automated Tsts下,选择Test Assembly并选择行尾的省略号按钮[...]。在“添加/编辑测试运行”对话框的“测试运行器”下,选择“Visual Studio测试运行器”。
-
After the build runs, the code coverage results are attached to the test run and appear in the build summary.
构建运行后,代码覆盖率结果将附加到测试运行并显示在构建摘要中。
Source:
-
Using Code Coverage to Determine How Much Code is being Tested (look for Analyzing code coverage in the build service)
使用代码覆盖率来确定要测试多少代码(在构建服务中查找分析代码覆盖率)
-
Run tests in your build process
在构建过程中运行测试
#2
When you are using Code Coverage for testing, you will determine how much of the project's code is actually being tested by coded tests, in this case unit testing. Code Coverage is a feature that Visual Studio uses to guard against bugs etc.
当您使用代码覆盖率进行测试时,您将确定代码测试实际上正在测试多少项目代码,在本例中为单元测试。代码覆盖率是Visual Studio用来防范错误等的一项功能。
Requirements are to have Visual Studio Premium
要求是Visual Studio Premium
To use analyze Code Coverage in Visual Studio on unit tests in the Test Explorer in Visual Studio, follow the steps bellow:
若要在Visual Studio中的测试资源管理器中使用Visual Studio中的单元测试分析代码覆盖率,请按照下面的步骤操作:
-
On the Test menu in Visual Studio select the option Analyze Code Coverage
在Visual Studio的“测试”菜单上,选择“分析代码覆盖率”选项
-
Then if you want to see which lines have been run, chosse the option Show Code Coverage Coloring
然后,如果要查看已运行的行,请选择“显示代码覆盖率着色”选项
The Code Coverage Results will usually show the results of the most recent run that you have done.
代码覆盖率结果通常会显示您最近一次运行的结果。
The code coverage can also be used to view previous results.
代码覆盖率也可用于查看以前的结果。
The coverage coloring might be incorrect if the source code has changed since the .coverage file was generated.
如果源代码自生成.coverage文件后发生更改,则覆盖着色可能不正确。
For automated Code coverage do the following steps:
对于自动代码覆盖,请执行以下步骤:
-
Select Test Assembly and choose the ellipsis button.
选择Test Assembly并选择省略号按钮。
-
In the Add/Edit Test Run dialog box, choose Visual Studio Test Runner.
在“添加/编辑测试运行”对话框中,选择“Visual Studio Test Runner”。
You can also Merge results from different Code Coverage Runs.
您还可以合并来自不同代码覆盖率运行的结果。
Here is a link if you want to Customize Code Coverage Analysis:
如果要自定义代码覆盖率分析,可以使用以下链接:
https://msdn.microsoft.com/en-us/library/jj159530.aspx
Here is a link for Analyzing Code COverage in Build Verification Test:
以下是构建验证测试中分析代码覆盖率的链接:
https://msdn.microsoft.com/en-us/library/jj159524.aspx
Here is a link for Troubleshooting Code Coverage:
以下是代码覆盖率故障排除的链接:
https://msdn.microsoft.com/en-us/library/jj159523.aspx
Sources can be found here:
来源可以在这里找到:
#1
According to info from MSDN:
根据MSDN的信息:
-
In Team Explorer, open Builds, and then add or edit a build definition.
在团队资源管理器中,打开“构建”,然后添加或编辑构建定义。
-
On the Process page, expand Automated Tests, Test Source, Run Settings. Set Type of Run Settings File to Code Coverage Enabled.
在“处理”页面上,展开“自动测试”,“测试源”,“运行设置”。将“运行设置文件的类型”设置为“已启用代码覆盖率”。
If you have more than one Test Source definition, repeat this step for each one.
如果您有多个测试源定义,请对每个测试源重复此步骤。
-
But there is no field named Type of Run Settings File.
但是没有名为“运行设置文件类型”的字段。
Under Automated Tests, select Test Assembly and choose the ellipsis button [...] at the end of the line. In the Add/Edit Test Run dialog box, under Test Runner, choose Visual Studio Test Runner.
在Automated Tsts下,选择Test Assembly并选择行尾的省略号按钮[...]。在“添加/编辑测试运行”对话框的“测试运行器”下,选择“Visual Studio测试运行器”。
-
After the build runs, the code coverage results are attached to the test run and appear in the build summary.
构建运行后,代码覆盖率结果将附加到测试运行并显示在构建摘要中。
Source:
-
Using Code Coverage to Determine How Much Code is being Tested (look for Analyzing code coverage in the build service)
使用代码覆盖率来确定要测试多少代码(在构建服务中查找分析代码覆盖率)
-
Run tests in your build process
在构建过程中运行测试
#2
When you are using Code Coverage for testing, you will determine how much of the project's code is actually being tested by coded tests, in this case unit testing. Code Coverage is a feature that Visual Studio uses to guard against bugs etc.
当您使用代码覆盖率进行测试时,您将确定代码测试实际上正在测试多少项目代码,在本例中为单元测试。代码覆盖率是Visual Studio用来防范错误等的一项功能。
Requirements are to have Visual Studio Premium
要求是Visual Studio Premium
To use analyze Code Coverage in Visual Studio on unit tests in the Test Explorer in Visual Studio, follow the steps bellow:
若要在Visual Studio中的测试资源管理器中使用Visual Studio中的单元测试分析代码覆盖率,请按照下面的步骤操作:
-
On the Test menu in Visual Studio select the option Analyze Code Coverage
在Visual Studio的“测试”菜单上,选择“分析代码覆盖率”选项
-
Then if you want to see which lines have been run, chosse the option Show Code Coverage Coloring
然后,如果要查看已运行的行,请选择“显示代码覆盖率着色”选项
The Code Coverage Results will usually show the results of the most recent run that you have done.
代码覆盖率结果通常会显示您最近一次运行的结果。
The code coverage can also be used to view previous results.
代码覆盖率也可用于查看以前的结果。
The coverage coloring might be incorrect if the source code has changed since the .coverage file was generated.
如果源代码自生成.coverage文件后发生更改,则覆盖着色可能不正确。
For automated Code coverage do the following steps:
对于自动代码覆盖,请执行以下步骤:
-
Select Test Assembly and choose the ellipsis button.
选择Test Assembly并选择省略号按钮。
-
In the Add/Edit Test Run dialog box, choose Visual Studio Test Runner.
在“添加/编辑测试运行”对话框中,选择“Visual Studio Test Runner”。
You can also Merge results from different Code Coverage Runs.
您还可以合并来自不同代码覆盖率运行的结果。
Here is a link if you want to Customize Code Coverage Analysis:
如果要自定义代码覆盖率分析,可以使用以下链接:
https://msdn.microsoft.com/en-us/library/jj159530.aspx
Here is a link for Analyzing Code COverage in Build Verification Test:
以下是构建验证测试中分析代码覆盖率的链接:
https://msdn.microsoft.com/en-us/library/jj159524.aspx
Here is a link for Troubleshooting Code Coverage:
以下是代码覆盖率故障排除的链接:
https://msdn.microsoft.com/en-us/library/jj159523.aspx
Sources can be found here:
来源可以在这里找到: