 Hi guys. So in this video, we're going to be taking a look at how to perform JUnit testing in VS code. So you can see here I have my class higher, which I created in my previous video. I'll link to that below. So the class higher just has one method higher. It takes two integers x and y and it returns the higher of those two values. So let's say I want to create a test to make sure my higher method is working as I expected to. I can do that by creating a JUnit test. Now you will probably need to do some additional setup in VS code prior to being able to get JUnit tests running correctly in the program. I did explain what you need to do in my video on getting VS code set up for Comp1010. It just involves creating a reference library in your settings.json. If you haven't seen that video, I'll put a link to that below as well so you can go ahead and do that. But assuming you've got everything set up, what you're going to do to create your JUnit test, the syntax is going to be as so. We're just going to go at test, just blur our method here. And then we're going to go public void test higher. And that's generally how the naming convention for tests is just test followed by a capital letter version of the method that you're testing. And then we're going to go assert equals, we'll say 25 higher. And we can say assert equals 5 higher. So what this means is when we test the method higher, we expect it to return 25 when it's passed the two values 25 and 25. And we expect it to return 5 when it's passed the values 3 and 5. Now obviously we can see here at the moment we're experiencing an error. And this is just because we haven't imported what we need to in order to get JUnit tests running. So let's go ahead and do that. If I just hover over test here first and I go to quick fix, it should be, yes, it's the option at the top here. So I'm just going to click that. And then I can do the same down here, just hover, quick fix, and we want to import assert dot assert equals. And now if we go up to the top, we can see that VS code has imported assert dot assert equals and JUnit dot test. And you can see we have now this option run test and debug test at the top here. And then we also have down below at our test run test and debug test. So now if I want to go ahead and run my test, I can just click run test right here. And you can see now if everything passes, all that will happen is a little tick will appear here. And if you look under here, you can see you have one next to the tick here and zero next to failures. So that just means that everything passed. So that's great. But let's say I made a small mistake when I created my method higher. Let's say instead of saying if x is greater than y return x, I've written if x is less than y return x. Now when I go ahead and run my test, you can see a little x appears here and this window will pop up. Now if I drop down this menu here, we can get a better look at what's going on. So you can see here we have the stack trace Java dot laying dot assertion error expected five, but was three. And if we just look down a little bit to here at higher dot test higher, this will tell you the line that the test failed on. So line 36 right here. So we can see that the test failed on this test. So that means that this one passed obviously because the error that I made didn't affect a test where the two numbers are the same. But it failed here. It expected five, but the test returned three. Now obviously in this particular case, it's pretty simple to see what's going on. We all know the mistake that I made. But let's say you weren't sure where the arrow had occurred, why your method wasn't returning what you expected it to. We can go ahead and debug the test. So I'll just exit out of this for a moment and I'm just going to place some break points along my higher method here. You can just single click on the margin here and it should work. Now very important, you also want to make sure that you move the test that failed or the test that you're trying to debug to the top of your method here. Otherwise it's going to test for all the other tests on top first. So I've gone ahead and done that. Now what I can do is I can click debug test. Now you can see the kind of interface has changed a little bit. So now if we look over here under variables, we can take a look at the current variables in our program. So we have x equals 3 and y equals 5. And then if we look up here, this button right here continue is going to allow us to step through each break point one by one in our program. So at the moment you can see it's highlighting the line that we're on if x is less than y. And so it's going to perform the test if x is less than y. So if we step through and then if we step through again, the program is going to terminate and we can see the test has failed because we've returned x. And obviously this is a very simple issue here. I can look and I can see oh, x was 3, y equals 5. 3 is less than 5 so I returned x. But obviously I know I wanted to return 5 so I can then say oh, whoops, I've written if x is less than y. I meant to test for if x is greater than y and now I can go ahead and fix that around my test again and everything will pass. So again, obviously that was a very simplified problem. But hopefully that gave you a general idea of how we go about performing JUnit tests in VS Code. So thank you for watching and I hope you found this video helpful. Bye.