在构建上自动运行单元测试

时间:2021-07-31 15:39:49

I would love to know if there is a way I can get Visual Studio to run unit tests corresponding to a given assembly whenever I build it.

我很想知道是否有一种方法可以让Visual Studio在构建它时运行与给定程序集相对应的单元测试。

Given a solution containing projects structured like this:

给出包含如下结构的项目的解决方案:

Assembly1

Assembly1.Tests 

Assembly2 

Assembly2.Tests

Is there a way I can get the unit tests in Assembly2.Tests to run whenever Assembly2 is built?

有没有办法在Assembly2.Tests中运行单元测试,以便在构建Assembly2时运行?

That would be amazing.

这将是惊人的。

I'm using Visual Studio 2008 Standard Edition.

我正在使用Visual Studio 2008标准版。

1 个解决方案

#1


18  

You can use the nUnit console utility to run the tests as a post-build event for the individual project.

您可以使用nUnit控制台实用程序将测试作为单个项目的生成后事件运行。

You call the nunit-console.exe and supply your assembly containing your tests as an argument.

您调用nunit-console.exe并将包含测试的程序集作为参数提供。

"C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit-console.exe" "PathToTestAssembly.dll"

“C:\ Program Files \ NUnit 2.5.7 \ bin \ net-2.0 \ nunit-console.exe”“PathToTestAssembly.dll”

or

要么

You can run the tests in the GUI:

您可以在GUI中运行测试:

"C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit.exe" "PathToTestAssembly.dll" /run

“C:\ Program Files \ NUnit 2.5.7 \ bin \ net-2.0 \ nunit.exe”“PathToTestAssembly.dll”/ run

Edit:

编辑:

Removed the part about the post-build event for the test assembly project.

删除了有关测试装配项目的构建后事件的部分。

#1


18  

You can use the nUnit console utility to run the tests as a post-build event for the individual project.

您可以使用nUnit控制台实用程序将测试作为单个项目的生成后事件运行。

You call the nunit-console.exe and supply your assembly containing your tests as an argument.

您调用nunit-console.exe并将包含测试的程序集作为参数提供。

"C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit-console.exe" "PathToTestAssembly.dll"

“C:\ Program Files \ NUnit 2.5.7 \ bin \ net-2.0 \ nunit-console.exe”“PathToTestAssembly.dll”

or

要么

You can run the tests in the GUI:

您可以在GUI中运行测试:

"C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit.exe" "PathToTestAssembly.dll" /run

“C:\ Program Files \ NUnit 2.5.7 \ bin \ net-2.0 \ nunit.exe”“PathToTestAssembly.dll”/ run

Edit:

编辑:

Removed the part about the post-build event for the test assembly project.

删除了有关测试装配项目的构建后事件的部分。