
422
|
Chapter 13, Enhancing Visual Studio
#93 Run Unit Tests Inside Visual Studio
HACK
namespace are executed by right-clicking inside a namespace and selecting
Run Test(s).
The Run Test(s) option is also found on various Solution Explorer context
menus. It can be used to execute all tests in a solution, project, or project
item.
Ad Hoc Tests
Ad hoc tests offer a useful alternative to throwaway console applications.
They should not in any way act as a substitute for real unit tests. Rather,
they are intended to provide a convenient way of exploring local private
methods or third-party code.
Any method that does not take parameters can be executed as an ad hoc test
simply by right-clicking inside it and selecting Run Test(s). It can be a pub-
lic, private, static, or instance method. In the case of an instance method, an
object will be created using the default constructor of the class (providing, of
course, that the class has a default constructor). The
Dispose method will be
called on any object that implements
IDisposable, once the test has been
executed.
If an ad hoc test returns an argument, the argument will be expanded to the
Test output pane. Complex objects will have their fields and properties dis-
played. Enumerable objects will be listed. Primitive objects will be con-
verted to strings and displayed.
Figure 13-3. Run Test(s) menu item