1 00:00:00,510 --> 00:00:03,880 I mentioned earlier that one of the great things about unit testing 2 00:00:03,880 --> 00:00:07,120 is it gives us multiple entry points into the code. 3 00:00:07,120 --> 00:00:11,630 This means we can start debugging the code just about anywhere we want. 4 00:00:11,630 --> 00:00:14,760 We don't have to run the software from where it would normally start and 5 00:00:14,760 --> 00:00:17,500 try to get it to stop at a given break point. 6 00:00:17,500 --> 00:00:19,100 Let's see how this works. 7 00:00:19,100 --> 00:00:22,910 We'll write another test, this time, for the InRangeOf method. 8 00:00:23,980 --> 00:00:29,810 So I right-click on InRangeOf, click on Create Unit Tests, Okay? 9 00:00:30,910 --> 00:00:37,400 I'll name this test method, InRangeOfWithRange1. 10 00:00:39,956 --> 00:00:44,580 I'll create the map object, you say var map = new Map. 11 00:00:45,660 --> 00:00:46,790 And again we use 3, 3. 12 00:00:46,790 --> 00:00:51,894 Our target will be the map location objects, 13 00:00:51,894 --> 00:00:57,020 so we'll say var target = new MapLocation. 14 00:00:57,020 --> 00:01:00,172 And we'll just have the MapLocation be at 0, 0. 15 00:01:02,337 --> 00:01:05,458 Now in this Assert.True, 16 00:01:05,458 --> 00:01:11,436 we'll say target.InRangeOf(new MapLocation. 17 00:01:13,313 --> 00:01:20,865 And this one will be at (0, 1), which is just one place away from (0, 0). 18 00:01:20,865 --> 00:01:26,710 So, we wanna check that it's in range of 1. 19 00:01:26,710 --> 00:01:28,065 There we go. 20 00:01:28,065 --> 00:01:31,564 Let's put a breakpoint right here in the InRangeOf method. 21 00:01:34,945 --> 00:01:38,973 Now, we can go back to our test, right-click on the method and 22 00:01:38,973 --> 00:01:40,270 click Debug Tests. 23 00:01:42,640 --> 00:01:46,000 This only runs the test method that we clicked on. 24 00:01:46,000 --> 00:01:49,380 As you can see, we've hit the break point in the in range of method. 25 00:01:50,580 --> 00:01:54,549 If we click the step over button and step out of the method, 26 00:01:54,549 --> 00:01:57,152 we find ourselves in the test method. 27 00:02:05,035 --> 00:02:08,250 We can also debug tests from the test explorer. 28 00:02:08,250 --> 00:02:09,960 Just right-click on the test or 29 00:02:09,960 --> 00:02:14,310 group of tests that we want to debug and then click Debug Selected Test. 30 00:02:16,640 --> 00:02:20,310 This is incredibly handy for debugging just the parts of the program we want 31 00:02:20,310 --> 00:02:22,475 without involving the rest of the project. 32 00:02:22,475 --> 00:02:27,031 Being able to begin executing anywhere in the code makes debugging quicker and 33 00:02:27,031 --> 00:02:28,110 easier. 34 00:02:28,110 --> 00:02:31,850 In fact, when I'm tracking down a bug, the first thing I usually do 35 00:02:31,850 --> 00:02:36,300 is write a test to reproduce it and then run the test in the debugger. 36 00:02:36,300 --> 00:02:39,830 This kind of flexibility is just another perk of having Unit Tests.