TIL: Letting Intellij Make Your Unit Tests
Intellij is such an overwhelming tool. It’s almost like opening up photoshop for the first time, with 500 different buttons and dropdowns everywhere and what am I supposed to do with this or that? That’s how I felt the first time I opened up Intellij.
Turns out, like with most things in Intellij, there’s actually a built in means to generating all of the test methods you could want, automatically, based on the methods available in your class! Yes, really! My mind was blown!
Not only that, but it’s super easy to do! All you need to do is go to your class, click on your class name, and then press
enter. This will open up a menu and one of the options will be to generate tests. If you hit enter on it a new screen will come up and give you a list of all of the methods present in the class. You can select the ones that you want, and then it will ask you where you want the file. Select the folder and you’re done!
This ends up generating a nice boilerplate file for you to start writing your tests in, with each of your methods being represented.
I went ahead and made a simple example tonight because I wanted to also get a hang of starting to write test cases. This was a super simple example, and didn’t really test any logic (just getters and setters). But it did make me learn about using the
@Before annotation to do setup before each test case.