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 - C# Tutorial
From the course: C# Best Practices for Developers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Project setup overview1m 13s
-
(Locked)
Set up the business layer2m 18s
-
(Locked)
Running a unit test3m 13s
-
Class naming conventions and standards5m 2s
-
(Locked)
Field and property naming conventions4m 22s
-
(Locked)
Using constructors3m 9s
-
(Locked)
Unit testing constructors4m 30s
-
(Locked)
Namespaces2m 48s
-
(Locked)
Static classes3m 10s
-
(Locked)
Unit testing static classes4m 20s
-
(Locked)
Using a singleton2m 6s
-
(Locked)
-
-
-
-