Writing an Actual Unit Test

You can start to see how you can leverage the unit tests that are generated for you. Let’s take a look at writing an actual unit test to help better understand them. Recall that a unit test is simply test code you write to call your application code. This test code asserts that various conditions are either true or false as a result of the call to your application code. The test either passes or fails based on the results of these assertions. If, for example, you expect an outcome to be true and it turns out false, then a test fails.

After you have a test project and a test class, there are three steps to creating a typical unit test:

1. Apply the TestMethod attribute to the test code.

2. Execute the code in question ...

Get Microsoft® Visual Studio® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.