But Wait - There's More / Unit Testing
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Now let's take a look at Unit Testing. This is a really cool function that has been built into Visual Studio, but there's a little confusion out there about actually how to set this up and get anything done with it. You can go out and look around the Internet, I'm going to just kind of kick you off and kind of get you warmed up with this, show you how to make it work, and let you use that kind of as a launch pad. First off, I've got my Hello World Project up here. Notice we've just got the same old standard code in there that we've been playing with and I think the last time I used this code was in the Refactoring video, so that's the last time you saw it look like this. But what I'm going to do is bring up the Solution Explorer and pin it up so you can see it the whole time, and then I'm going to show you how we could run some Unit Tests on this code. Now these Unit Tests won't be complete. I don't have enough code here and I don't have it set up and I know I don't, I don't think I have anything passing, parameters, so that's going to be, anyway, we'll just run it and let you see it. First of all, to run Unit Tests on any of this stuff I need to set a Unit Test Project up in here and so what I'm going to do is I'll just, on the Solution Explorer over here I'll click on my Project. I will come over here and I'll do: File, New, Project, and I want to show you, we talked about this in a different place in the Course, I will point it out again. In the Solution it's saying: Where do you want to put this? Create a New Solution? And I'm going to say no, Add it to this solution. OK? And then I will come down and notice, Test and I will add a Test Project. And it'll take a minute. It'll click and hum, and I'll look at the hourglass and I'll let this happen. And so notice, now you'll see that I have a TestProject inside my Solution along with my Hello World Project, OK? And it'll take him just a minute to get everything set up and you'll notice some other things are showing up here now, and it's writing some classes and codes for us, and so now this is the way it finally looks. It brought up for me a Text File that tells me how to do some things about viewing tests and running tests, and there's a lot of information here and I would strongly recommend you go out and get this and play with it. I will close that. Here is a Unit Test VB file that's out here, OK, and what I will do is go into my code now, OK, and notice I will right-click on CBF ButtonColor and notice I can see Create Unit Tests, OK, so I will create Unit Tests and you will notice that it's going to click and hum and I will see an hourglass once again. And it'll take this a few minutes to get it all up there, and if I expand it you will see all the things from Hello World that it could test. OK? And I'm just going to, I'm going to click some of these so you know what, yeah. Test this stuff, too. OK? This, you create Unit Tests for all these, and then I will click OK, and notice it's generating the Test method, it's writing my Test code for me, and the world of testing has exploded, and it's turned into a science. And now it's telling me that I've chosen to generate tests, you know, for a type that's marked as Friend or Internal, it's talking about that class that I have down there called Public Class TestThat, and I'm not going to go along with that for some reasons we won't get into here, and so now you see that I have a Test TestThat.VB and then I have my UnitTest.VB, and so forth. So let's go back to my Form, my Form1 Test.VB now, and I can come down here and notice on these test methods, for example on my ChangeButton TextTest I can right-click that and click Run Tests, and notice some builds are going to succeed, some tests will run, and in just a minute I'm going to get a Test Results Window pop up Ð there it is Ð notice the Test is in process on that, and it's telling me that it's inconclusive. A method that doesn't return a value cannot be verified. In other words, it needs to be a function. But anyway, I can double-click this at any time, and it will give me some more information on my results, OK? So, again, I'll just close that. I can go back into my Form1 Test.VB, OK, and I can scroll down and grab something else, my ColorTest, again, right-click it, Run Tests, and again, this one's going to be inconclusive because of the way, I don't have a very well developed program here, but that's how you test, OK? And notice your Test Project will stay in here, and a very easy way to just go through and right-click, test my methods. OK, now, testing again gets to be a deep, involved subject and you'll need to educate yourself, but I just wanted to see, wanted you to see, how to kick this off, and I just kind of barely got you up out of the water here, OK? So, go out, play with some of the testing functions, and I hate to tell you in every video that you need to read some more, and read some more, and read some more, but that's exactly what you do, I'm afraid. So, anyway, there's a brief introduction to Unit Testing, so again, start to educate yourself and start to jump into the world of testing. It's kind of become the way we do business nowadays because of the way our Applications are being carried out and because of the importance on these applications, and just the sheer danger of logic errors and what they can do to us. So anyway, there's Unit Testing.
Tutorial Information
| Course: | Introduction to Microsoft Visual Studio 2008 |
| Author: | Mark Long |
| SKU: | 34008 |
| ISBN: | 1-935320-54-8 |
| Release Date: | 2009-06-26 |
| Duration: | 7 hrs / 72 lessons |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 