Writing a Unit Test

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 to be false, that test would be a failed test.

In broad strokes, there are three steps to creating a typical unit test:

1. Apply the TestMethod attribute to the method you want to be treated as a test.

2. Write code in your test method to execute the code you want to test, passing in known values if there are parameters.

3. Write assertions in your test code to evaluate the results ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition 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.