Archiwa tagu: test

How to run tests in Visual Studio?

How to run tests (unit tests, Selenium or any other in Microsoft Visual Studio? This is quite simple.

My instruction is for Visual Studio Professional 2015.

  1. First – choose test runner (nUnit, MSTest, xUnit or other). I choosed nUnit, because of its popularity.
  2. Install a test runner. I use NuGet to manage dependencies in my projects. To install nUnit, click (right) on project and click „Manage NuGet Packages”, search „nUnit” and install it. A current version number is 3.4.1.
  3. Prepare a simple test. Remember about:
    • making class containing tests public (public class TestClass{})
    • making test methods public (public void TestMethod(){})
    • marking test methodss with [Test] attribute.
  4. Prepared test should be visible in Test Explorer (open this window from menu: Test -> Windows -> Test Explorer). If Test Explorer window is empty and after building project Visual Studio doesn’t display any tests, you need to install nUnit Test Adapter (version 3.x is compatible with nUnit 3.x). To install nUnit Test Adapter, choose „Extensions and Updates” from „Tools” menu, search for „nUnit Test Adapter” and install it. After rebooting Visual Studio and rebuilding project, tests should be displayed in Test Explorer Window.