Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic running of unit tests on build

Tags:

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.

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?

That would be amazing.

I'm using Visual Studio 2008 Standard Edition.

like image 352
David Avatar asked Aug 13 '10 08:08

David


People also ask

Can unit testing be automated?

Unit testing can be done manually but is usually automated. Unit testing is a part of the test-driven development (TDD) methodology that requires developers to first write failing unit tests. Then they write code in order to change the application until the test passes.

How do you make unit test cases automatically?

To generate unit tests, your types must be public. Open your solution in Visual Studio and then open the class file that has methods you want to test. Right-click on a method and choose Run IntelliTest to generate unit tests for the code in your method. IntelliTest runs your code many times with different inputs.

In which build phase are unit tests run?

Unit Testing is done during the development (coding phase) of an application by the developers. Unit Tests isolate a section of code and verify its correctness.

Should I run unit tests before build?

Always build the project(s) before running/debugging unit tests. Positive: always correct results, not confusing for users.


1 Answers

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

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

"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:

"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.

like image 82
fletcher Avatar answered Oct 02 '22 11:10

fletcher