Breakpoints12:55 with Craig Dennis
Let's take on our first issue. We'll use some powerful breakpoint tricks to get through things.
Sample Email about tests
Things are going good, and we are cruising through the issues you have filed for us. We're getting in there and learning how things are working. I am really enjoying your FlashCard app, I'm certain your students will love it.
We did uncover a slight snag in the plans. A common development practice is to write code that actually verifies that the application is working the way that it was intended. This practice is called testing. Unfortunately the developers writing your initial prototype opted not to follow this process.
The good news is that we can fix this and start employing the testing practice moving forward. The bad news is that it will take additional time, and I do realize you are on a tight budget. My colleague and I are very fond of testing, and employ it on every project we create. We do this because it helps make sure that any change we make did not break any other part of the application. Every feature we write will be thoroughly tested and that allows other developers to understand how your requests are supposed to be working. Seeing as you don't have a specific team of Quality Assurance people, there are bound to be possible issues not yet reported.
We have already spent some more time than we would normally need to if we had tests in place. In the future, it will for sure speed up development. However, setting up tests is indeed an upfront investment, and is completely your call.
I estimate we can get your application tested in 2 days, and again like I said I understand your tight budget, I'd just like to make sure your application is healthy and you have the ability to rapidly iterate on your awesome project.
Let me know your thoughts. Happy to discuss it more!
PS. There's a great motion example on Treehouse around the 3 minute mark ;)
Okay, so let's tackle this issue here. 0:00 This is issue number 6, and I'm gonna go ahead and assign it to me, there we go. 0:03 Now since this is a git repository in my team, that's you, 0:10 you could be working on something else. 0:14 I'm gonna do all my work in a brand new branch, and 0:15 I'm gonna keep my changes separate from what's happening on the master. 0:18 So I'm gonna do that by creating a new branch down here, I'm gonna choose 0:22 New Branch, and it should be something similar to what the topic is, right? 0:25 So the topic of that issue is fewer-examples, right, 0:29 we want it to go from five to three. 0:34 Okay, so that code that we saw, 0:36 what we wanna do is we wanna just change this to three, right? 0:38 Why don't we leave things a little bit cleaner than when we found them? 0:42 I mean, so remember how we wanna share with that fiber represented when we 0:45 first saw this? 0:48 Let's make this a constant so the next person will for sure understand. 0:49 So one thing to do is you can choose this choose it and choose Refactor, Extract, 0:53 Constant, and then we’ll get rid of that magic number that was there, right? 0:59 Let’s call this AMOUNT_TO_ SHOW. 1:02 And that created up here, created a new public static final entity now to show. 1:06 Cool, so now everybody can access that and it reads cleaner. 1:09 No more magic numbers. 1:13 I'm gonna go ahead and I want to leave this breakpoint here in case I want things 1:15 to stop and I do wanna run this in debug mode just in case we forget, 1:19 in case something didn't work like we wanted. 1:23 So I'm gonna choose the Debug app, and while 1:25 all this is going and debugging, I can come over here and I can do this thing. 1:31 I don't want it to stop, I want it to run. 1:35 So I can do a thing called muting breakpoints and 1:37 that's this thing over here. 1:39 I'm gonna mute the breakpoints. 1:40 So I'm gonna click this. 1:41 Notice how it got grayed out here. 1:43 So now it won't stop, it's not enabled, is that word for that. 1:44 Cool, so I'm gonna go and refresh the page. 1:50 There we go, and there's three, awesome. 1:54 And they're right, it does look better. 1:56 I like that there's only three, but there's eight more. 1:58 That total is off, we've got to fix that. 2:02 So let's do this. 2:05 Let's come back. 2:06 Let's go ahead and unmute, and see how it turned red again, and I'm gonna refresh. 2:07 And boom, here we are back, and I'm gonna go ahead and 2:13 I'm gonna drop a line right here on this and, line. 2:16 And one thing that we can do is we can continue to that breakpoint since one 2:21 exists, this will resume the program and will hit the next breakpoint, boom. 2:24 So what was this doing? 2:29 Right, it's getting the total count and it's appending the total count. 2:31 Now before I change this, why don't we fix we know that we got the three thing 2:34 working and that's a good unit of work. 2:38 Let's make a commit first, right, so I'm gonna go to version control here, and 2:39 I'm gonna click this VCS button here which is for committing changes or 2:43 some other things that have been changed. 2:48 So I'm gonna unclick this miscellaneous because that's not related to what this 2:50 commit is about. 2:53 So let's see the commit message for this. 2:54 Let's think, it's addresses issue number 2:56 6 by changing the number of examples to 3, cool. 3:03 So I'm gonna go ahead and commit that and 3:10 we've been warned that there is some possible things wrong. 3:13 I'm gonna go ahead and not do that cuz I'm pretty happy with where things are at. 3:16 I wanna choose Commit. 3:19 And I wanna say No, it's talking about the miscellaneous thing there. 3:22 We'll take care of that later. 3:26 Okay, so let's tackle our next problem. 3:28 So we have the total but it really should be the total without the things that have 3:30 been shown and thankfully now that we have that constant we can use that. 3:35 So if we say the total amount to show there, 3:38 let's get this back and they debug window here and I'm gonna go ahead and 3:43 restart the debugger because we just changed that code so let's do that, and 3:49 I don't want it to stop at this first one, but I do want it to stop there. 3:53 So I can actually right-click this and 3:59 choose that one specifically to be disabled, right? 4:01 So see how it's got a little different thing versus the muting of it. 4:06 So I'm gonna go ahead and let's refresh. 4:09 Okay, so, you know what, actually what if we come in here and 4:14 the amount to show is more than the total count. 4:19 Now since we don't have tests in place, 4:22 we can't really easily reproduce that situation to see what happened, but 4:25 what we can do, is we can fudge the numbers, right? 4:28 So we can fudge what total count is, let's go ahead and do that. 4:32 So I'm gonna step over once more, and you'll see the total counts down here, and 4:35 you can actually fudge these numbers, it's kinda cool. 4:39 So check this out. 4:42 So you right-click here, and just use Set Value, and total count is a long, 4:42 so I'm gonna press 1 and then L to represent a long. 4:47 Okay, so now total count is set as a long. 4:50 And so when this goes through here, it's going to, we can see what happens, 4:53 right, so let's do that. 4:58 Let's take a look. 5:00 Uh-oh. 5:01 Refresh your memory about those and -2 more. 5:03 Yikes, that's horrible. 5:07 We have to make sure that doesn't happen, right? 5:09 So that sounds like a good job for an if statement, right? 5:11 So let's go ahead and I'm gonna move the total count line up. 5:13 And that actually wiped out the debugger, 5:19 I wanna press stop on the debugger and let's go ahead, 5:21 I'll add a debugger line there and we're gonna add an if statement here. 5:25 So what is that if statement, so if 5:30 the total count is greater than the amount to show, right? 5:33 As long as there are some left then we should show and, right, 5:38 that seems to work. 5:43 I’m going to move these lines up and we pressed tab, there they go. 5:44 Now before we kick this off, 5:50 I wanna show you a couple of breakpoint options that we have. 5:52 So if you click down here, you can see View Breakpoints and 5:55 will show you all of the breakpoints that you have currently open and 5:59 you can see here this one is disabled and this one is not and 6:02 you could imagine as you get better at this they're gonna be all over the place. 6:05 And it gets unmanageable to flip between each file and enable and 6:09 disable like we just did. 6:12 So this grouping here is kind of a lifesaver, right? 6:13 So this goes between packages and this one goes between files and 6:16 this one will group just between classes them self. 6:20 So it's nice with these groupings if you wanna disable all of these you just check 6:24 that and you could do that per file, right? 6:27 So if you had other files they'd be showing up here and 6:29 you can turn off just this file, turn this one on. 6:31 So the next stop in is that you can have a breakpoint 6:33 that doesn't suspend execution, right? 6:37 So let's do that first point that we have in here right where it 6:40 stop them in the ctaBuilderlet, let's make it not suspend but 6:43 let's actually make it log a message to the console. 6:46 Okay, so what happens then is when that line comes through, it's going to 6:48 write out what happened and what will take a look at it here in a second. 6:52 The other thing that you can do here, so this is handy for 6:55 when you're in sort of in a loop and you don't wanna actually pause on each thing, 6:58 you might wanna come in here, let's go let's drop a breakpoint here and 7:02 you can get to that screen also by right clicking and choosing More here. 7:06 So let's see that specific break point that we just dropped is here and 7:11 we also don't want this thing to Suspend but we're also gonna here, 7:16 let's log, we can use a Java statement here and we can say, 7:20 card definition is,.and you can just, you have access to what has it 7:25 ever in your current state there and all the awesome autocomplete. 7:29 So basically, that's the system print line message [LAUGH] that you littered all over 7:35 the code normally but here you can just be stored there in that break point. 7:38 Pretty nice, right? 7:43 So remember these first two are set to not suspend and 7:45 this third one is where we're going to stop. 7:48 So I'm gonna go ahead, I'm gonna restart the debugger and 7:51 if I come over here and refresh, we're gonna pause, right, 7:55 it went right through these two and it stopped here on the total count. 7:59 Awesome, right? 8:03 And if we look over here in the console, we can see that the breakpoint was 8:04 reached, and it has a link to where that breakpoint was happening, 8:07 that's what it looks like when you don't suspend it, you just log it out, and 8:11 then this is the evaluated expression. 8:14 Pretty cool, right? 8:16 So much handier and better than lettering your code with system help print lines. 8:17 Well, since we're here, let's once more, 8:22 let's change this value of what that total count is. 8:24 So let's get back to our debugger, total count here were set to 8, 8:27 we're gonna change this to be 1L and I will continue through. 8:32 There we go, so 8:38 it doesn't say and how ever many more because they're not there, awesome. 8:38 Now we are ready to commit that change so let's go to our version control and 8:44 we'll choose this. 8:49 And we'll make this also not include this 8:50 miscellaneous and we'll say, 8:55 Addresses bug described in number 6 where 8:59 the total count in the call to action was off. 9:04 Cool and I'm gonna choose commit and I'm gonna choose commit and 9:12 push this time because I'm gonna push this up to GitHub. 9:15 This is a common practice, I'll show you here in a second. 9:18 So we'll commit and push and we'll say Commit. 9:21 And this is saying here that on it's gonna create a new branch called fewer examples. 9:25 So that's what we want, we're gonna push that up to GitHub, let's push that. 9:30 So now if we go to GitHub and 9:37 we take a look we'll see that there's a new branch that has been pushed up and 9:38 it's asking me if I want to compare and do a pull request and I do indeed. 9:42 Now by default that's gonna go try to jump across the fork but I don't I don't want 9:46 to go across the fork, I wanna do this in our branch here first. 9:51 So let's do this, let's change the base fork to be mine, 9:54 not the master treehouse one, right? 9:58 Okay? 10:01 And it's now, tell me that it's able to merge and I'm doing this cuz I wanna 10:03 share it with you, so this is fewer examples on the homepage and says, 10:06 this is directly related to number 6. 10:11 I got it figured out, all right, something in here. 10:15 Also fixed weird total bug, and 10:21 so I'm going to do this and it will show you in here all the changes that 10:26 were made in notice that it's linking here. 10:31 So I wanna go ahead and create this pull request, And let's imagine that 10:33 you come in here and you wanna look at the commits that I did and 10:38 then you wanna come to the issue and take a look at the issue and 10:41 you can also see that now If you walked into here, it comes in here. 10:45 So you can see that the six is here. 10:50 So let's go ahead and look at the pull request. 10:53 You came in here. 10:58 You look at it. You say that that looks great and 10:59 you're gonna choose merge pull request. 11:02 And you're going to confirm the merge. 11:05 So now, master has the merge request, thanks. 11:10 Let's take a quick look one more time at those break point options, okay so 11:15 if I come back and I come into our break point options One thing that I wanted to 11:18 show you here on the suspend is that there is all and there is thread. 11:23 Our spring application is in fact multi-threaded, so 11:29 the server can continue running and handle multiple requests. 11:32 Now what we've done here is we've stopped all of the threads. 11:36 You can actually navigate through the threads down here. 11:39 See how they have these different threads and 11:43 if you ever got lost in these different places you can always find the little one 11:45 with the check mark to get back to the thread. 11:49 So our web applications are probably never ever going to do that but there 11:51 might be other applications that you're running where you want to pause a single 11:54 thread just to keep the rest of the world moving Now that we have a vibe for 11:57 what is happening, we really should contemplate writing tests. 12:01 But doing that extra work, you know, taking the time to get unit test up and 12:04 running, well, that might end up completely blowing out our time estimate 12:07 that we agreed upon with the client. 12:10 Now, don't get me wrong, it most certainly will save us time in the future, but for 12:12 now, that's not really our call, right? 12:16 Let's do this. 12:19 Whole shoot the client an email explaining that we really should be writing test. 12:20 And explain the benefits of testing and yada yada. 12:24 And we'll see if that's something that they're interested in investing it. 12:26 I'll do my best. 12:30 All drop the email in the teacher Teachers notes here when I'm done just so 12:31 you can see how to approach this delicate issue 12:33 that is if you're interested it happens quite a bit. 12:36 I'm glad we're taking the time to explore the debugger it's a really powerful tool 12:39 and the more you know what it's capable of doing the more you'll use it. 12:43 Let's take a quick break and then come back and explore frames and 12:46 how to rewind history. 12:49 Don't worry we'll deal with the oddities of time travel with the greatest of ease 12:50 thanks to our debugger. 12:53
You need to sign up for Treehouse in order to download course files.Sign up