3

I have heard about unit test in VS. Many persons of this community tells that create unit test will improve your OOP designs.

I really have no idea of it. Can you know a web site o example about how to create it?

DOK
  • 32,337
  • 7
  • 60
  • 92
Darf Zon
  • 6,268
  • 20
  • 90
  • 149
  • 1
    possible duplicate of [How to start unit testing or TDD?](http://stackoverflow.com/questions/1365943/how-to-start-unit-testing-or-tdd) – Paul Sasik Jan 29 '12 at 17:07

2 Answers2

5

Provided you have the correct version of Visual Studio (I believe it's a minimum of Professional that includes the ability to Unit Test), you just create a new project (preferably using the Test template). Referencing your code that you want to Unit Test, you write TestMethods that will Assert() what you require to be true.

You can also pull up the Test View, which will list out all of your Unit Tests so you can Run/Debug them on the fly.

A Unit Test is really just a code library that uses the Microsoft.VisualStudio.TestTools.UnitTesting namespace (Note: this is for MSTest, which ships with VS. There are many other Unit Testing tools/libraries out there).

For further details, please see this MSDN article: Walkthrough: Creating and Running Unit Tests.

4

You definitely do not HAVE to use the Visual Studio test tools. I have heard from various sources that the test engine is slow compared to NUnit.

I'd say NUnit is probably the most-used unit test engine for .Net. xUnit, its successor (by the same team I believe) is also gaining popularity.

Are you asking about unit tests specifically, or about test-driven development? Do you know? Unit tests are a technique - and many including myself would say a vital one. Test-driven development is a philosophy. Therefore the latter is likely to need buy-in from your team.

Tom W
  • 5,108
  • 4
  • 30
  • 52