 Hi, so now we're gonna get started on the automation part of software testing in the previous videos We thought about testing using our human intelligence and now it's time to make the machine to run those tests for us And we're gonna use J unit, which is the standard way of writing unit tests in Java And so let's get started So we have the Roman numeral problem and this is my implementation You don't really need to understand it now because we are now using the testing hat But if you really pay attention or if you'll quickly pay attention You can see that my implementation is about getting the current number Then I look to the next number and then I decide if I should add Or if I should subtract because because of the subtractive notation that we discussed But now let's testers. We just want to make sure that this works So what I'm going to do is create a different class. So the roman numeral tests and I put this in the test folder Usually that you can see on the left side of my IntelliJ So in the roman package, I have the class there and it is empty So let's get started with J unit. How does this work? It is very simple We basically write methods and these methods will do the test for us So the first one will be I want to try a single number So I create a method. It has to return void And it has to be annotated with add test And I'm going to import this from orc junit jupter api because I'm using the junit 5 version And this add test indicates to junit that this is a test Then the first step is I need to instantiate the class I want to test and in this case is the roman numeral class I'm going to start this into a variable and I'm going to call it just roman The second step is to invoke the method we want to test. So roman.convert And I'm going to pass now a single number. That is the test I'm doing right now. So I for example And I know that in roman numeral This result it needs to be equals equals to one But that I'm going to write using the junit functionality, which is assertions Dot assert equals Then I pass what I expect which is one and the variable that stores the result. So Which which is named result? So take a look at this because all your unit tests will look like the same So we basically think about one of the cases In our case we started with a single number that we discussed in the previous video I invoke the method I want to test passing this data I get the result And then I assert and that's the verb we use we assert that the result is as we expect So I need to be one IntelliJ already knows how to play with junit. So as you can see there is even this green Run button in here Run test as it says if I click on it and then I click on run single number IntelliJ will automatically run this test for me And you see the green results at the bottom of my screen So this means that IntelliJ executed this method It compared the result with the number one And they were the same. So this means For these behavior my software works as expected. So we say that our tests are green and then this means we are happy But one test is not enough in the previous video. We came up with many, right? So let's go to the second one I'm gonna minimize this and I'm gonna write the next so at test again void and The second scenario I'm gonna automate is when I have more than one digit. So like vi for example, so number with many digits And this is a nice information the name of the method doesn't matter So as developers we use these to try to express what we want to test So number with many digits is my case. I'm gonna again create the roman numeral class That's the class I want to test. I'm gonna invoke the method and now I'm gonna pass for example viii Let me start this in a variable I'm gonna start this in the result and I know that viii in roman is eight So again assertions assert equals Eight results I have a button here. I'm gonna run it again Or actually for the first time this is the first time I run this test and wow It is red right now and this means that junit executed my test But then the result was not eight and this is a bad sign, right? This means that I have a bug in my software and as a developer This is actually a good thing because I found this bug before sending my software to production My found my final user didn't see it So what we need to do is to go back to the source code and find the bug So pause this video and try to find the bug Okay, I'm back and the bug is actually here. So it shouldn't be just greater than but greater than or equals Pause this video understand why but that's that that is the bug and That's a common bug, right? We have been discussing that developers do lots of these kinds of bugs And yeah, this is just another one So I fixed the bug what I usually do is to run it again to see if I really fixed it Result is green Another tip for you as a developer. I'm just running one test as you can see in in in my left bar But it's nice if you run all of them Nice the two testers are passing Let's just write one more So add test again Uh void Now I'm gonna play with a number with a subtractive notation And if you remember the subtractive subtractive notation is The thing in roman numerals that you need to put the numbers before You're gonna see it now. So I'm gonna create the roman numeral again I'm gonna convert and the number I'm gonna try is iv Let me start this so iv and then this number is four, right? So let's make sure It is four and we do this by means of assertions So the result needs to be four And this is actually the order that you pass the parameters. Okay, it seems Not intuitive, but it's what you expect and then what you calculated. Okay, so four result and no and not result four Let's see if our software works running the tests They all run and uh, also pay attention how fast it is IntelliJ says that it took uh, 27 milliseconds to run. This is definitely faster than a human, huh? Okay, so the three tests are green and this means so far our our implementation seems to work And what I want you to do now is to continue writing many tests in the previous video We thought about many of them your task is to continue So this is a very simple introduction to junit Throughout the course you're gonna see more features junit is an amazing framework. Go look at the documentation But this is what we will do From now on so we're gonna discuss how to think about tests using our intelligence The the human the human part of doing tests as we discussed And as soon as we have tests at the testing hands, we're gonna automate it Always always always using junit. Yeah, ready for it. See you in the next video