Getting started with configuring the testing project

Open your Visual Studio 2017 IDE, go to File | New | Project| Console App (.NET Framework) as the project template. Create the project by giving it a name (in this example, we are naming it ConsoleApp).

Now, create a class named Person and inherit it from the ICloneable interface (just for this demonstration). Implement the interface to generate a Clone() method, which will by default throw NotImplementedException. Leave it as it is; we are going to revisit this method later. Add few string properties named ID, Name, and Address. Here's the implementation of the class, for reference:

    public class Person : ICloneable 
    { 
      public string ID { get; set; } 
 
      public string Name { get; set; } 
 
      public string Address { get; set; } 
 
      public object Clone() 
      { 
        throw new NotImplementedException(); 
      } 
    } 

As we have our Person class in our application project, let us create the unit testing project for testing and code coverage. Right-click on the solution file in Solution Explorer and navigate to Add | New Project... from the Visual Studio context menu. This will open the Add New Project dialog on the screen. Select the project type Unit Test Project (.NET Framework) from the Test category, give it a name (for example, TestConsoleApp) and click OK to create the unit testing project in the same solution:

Once the unit testing project gets created in the solution, add the assembly reference of the main project into it to refer the classes available there. Right-click on the unit testing project and, from the context menu, select Add | Reference. From the Reference Manager dialog window, navigate to Projects | Solution and then select the projects that you want to add as references. Finally, click on OK to continue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.28.197