简体   繁体   中英

How to do unit tests in VS?

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?

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 TestMethod s 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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