From the course: Java: Testing with JUnit
Setting up JUnit for IntelliJ
From the course: Java: Testing with JUnit
Setting up JUnit for IntelliJ
- In this clip, we're going to set up JUnit for IntelliJ. We are assuming that you have your Java environment setup already. If that's the case, it's very easy to add JUnit to your environment. First, we're going to create a new project, we're going to add a Maven dependency to this project, and then we'll quickly test the setup. Let's move over to IntelliJ. So first we're going to create a new project and we're going to do so using Maven. I'm going to click next. And if it's prompting you for a group ID and an artifact ID, you can just fill it out. It doesn't really matter what you put in there. And I'm going to give our project a name. And I'm going to name it, set up JUnit IntelliJ. And now I'm going to click finish, and it's going to set up two projects for us. Here, we can see the bump of a project. And as I already mentioned, we'll have to adjust this bump in order to add JUnit to our project. So I'm going to be creating a dependencies list. And in here, I'm going to create the dependency I need. And it's the org.junit.jupiter. It's already completing it for me. And well I don't need to engine actually, I'll just need the junit jupiter. And the latest version right now is, I think 5.7.2. But it's not unlikely that by the time you are writing this, there's actually a later version available already. So let me show you how to check for the latest version. We are going to go to mvnrepository.com. And in here, I'm going to be looking for JUnit Jupiter. And in this case, we need the third one, which is just the plain JUnit Jupiter. And I'm going to click on it. And as you can see, there is already a 5.8.0, but I don't want to use this version right now. I want to go for this one. I have that one ready, but if you have a later one that you'd like to use, you can just click on it and then copy the dependency here, and paste it inside your project. You can also find the latest version in the JUnit docs. So let me go to junit.org and show you. Here we have junit.org. And in here, if we click on user guide, we actually find lots of documentation. And what I'm looking for right now is in the appendix. We want to have look at the dependency metadata, and then we want to click on this one. And here we can see on top of the screen is the latest version in the junit docs is 5.7.2. All right, enough digging into documentation. Let's go back to our IntelliJ project. I have added this dependency right now, but I did not update Mavin yet. I could just click this floating one over here. If it's not there, you can open this one, click download resources and then update your projects. But for now, I'm just going to be clicking on this one because it's good enough. All right, let's test our set up. I'm going to go to our test folder, and I'm going to be creating a, well a test test pretty much. (chuckling) So let's go call a test, test, since we're testing a test. And in here, I'm going to be creating a very basic test. I'll just call it the like void test like this. It doesn't need any content actually. I just want to see what a JUnit is running. And I'll annotate it with tests. And please mind that you are using the test annotation from org.junit.jupiter.api like this. And now we should be able to run our tests. In the lower left corner, we'll see green checks. Yes! And that's great. We're all set to get started now. It's time to write our first test in the Hello World JUnit video at the end of this chapter. So please move on to the last video of this chapter to write our first JUnit test.