From the course: C# Best Practices for Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unit testing constructors

Unit testing constructors - C# Tutorial

From the course: C# Best Practices for Developers

Start my 1-month free trial

Unit testing constructors

- [Instructor] So we're ready to create our test and I will go ahead and create a test called Test Parameterized Constructor. I'll start off by my annotation. Public void Test Parameterized Constructor. And of course, we'll be doing some arranging, acting and asserting. We'll start off by defining a current actor and creating an instance of actor where we pass into the name, Johnny Boy. Then our expected value is Johnny Boy. To get that value, we want the result to come from whatever's in the property name, ActorName. At this point, we can assert to see if, indeed, our expected is equal to the result. Now, I'll go ahead and save. To run the test, I'll go ahead and set a break point here. In our Test Explorer, I'll right click on TestParameterizedConstructor, and choose Debug Selected Test. Now when I step through and get on line 30, I can compare whether the expected, which is Johnny Boy, is equal to result, which is Johnny Boy. Perfect, so now when I hit Continue, our test should…

Contents