Join Reynald Adolphe for an in-depth discussion in this video Unit testing without parameters, part of C# Best Practices for Developers.
- [Instructor] OK, so we are ready to create our test. Let's go ahead and hop on over to our actor test, but, before we do, I'm gonna copy this line, here, booking can change if actor starts trouble, because I'll be using that line. And, in our test file, our first test method will be for booking the actor without any specific date.
So, we're not returning anything. The name is BookActor, but let's call this TestBookActor, and follow the convention. All your tests should indicate that you're testing, just to be consistent. And, we will be arranging our details.
And, we know we will Act and Assert, so I'll just put those in, right now. But, we're not done arranging, yet. I'm going to use the variable currentActor and create a new instance. And, we're going to be passing in the actor name.
And, for expected, we want the statement to say Actor Johnny Boy is booked, followed by details, indicating that, if he starts any problem, he's out. And, to get our result, I specify the currentActor, and invoke BookActor.
And now, let's check to see if these two values are equal, comparing what we expect and what our results are. So, I'll go ahead and check to see if our test works as expected. And, it doesn't, let's see what's going on, here.
I'll click Debug, and choose Debug Selected Tests. And, let's begin stepping through. Actor Johnny Boy is booked, booking can change if actor starts trouble. Actor Johnny Boy is booked, and booking can change if actor starts trouble.
I see two differences, here. One is a capitalization of is booked, and then, also, there's a space that's not there for booking can change. So, let's go ahead and fix that. And, right here is where I need to modify the capitalization and add a space. So, let's go ahead and run this again.
And, there we go. So, now, we're ready to test our next method.
- Naming and handling classes
- Running a unit test
- Using constructors
- Naming and handling methods, fields, and properties
- Using properties correctly
- Managing objects efficiently
- Common design patterns as best practices