Running Your Tests?

Course Home | Code Example(s)

So we’ve written many tests, but how do we run them? Good question. We actually have many ways we can run our tests, so let’s explore them.


We can run tests directly from IntelliJ. Not a great solution for CI, but very good when creating the tests, and testing them. IntelliJ has a JUnit plugin, I believe it ships as part of IntelliJ, but you can check your have it by going to Preferences > Plugins and you should have one called JUnit. If it’s not there, you can google it and add it. Then all you need to do it right click on a test and click ‘Run '. It will then execute the test. It will also bring the 'Run' window into focus. So you can see the console and progress of your test. Or if the test is in focus you can press Fn + Shift + F10 (Mac).


We can use Maven to run our tests by typing ‘mvn test’ in a console window while in the project folder. Now Maven is old school by default, it will only look for tests in class that are named Test*, *Test, *Tests or *TestCase. So if you try this and no tests run, that will be why. If it doesn’t pick up tests you’ll see this in the console

Maven Test Console

So if you follow the above naming convention then ‘mvn test’ has your covered. Otherwise, we have another way.

Maven Surefire Plugin

Maven has created the Surefire plugin. Now if using Maven and Java, I’d encourage you to use Surefire to run your tests. It provides a lot more control than just using default ‘mvn test’.
To install Surefire, you just need to add some XML to your POM file.


The first advantage of this is that we can inform Surefire of classes that contains tests, that don’t fit the naming convention, by adding this within the tag.


Another thing people always want to do in run tests in Parallel. We can do by using the tags, by adding:

<threadCount>10</threadCount> <!-- Number of tests to run in parallel. -->

I may add some more advanced posts on Surefire, but for now, I feel this is enough. I encourage you to check out the official documentation. Especially if you are looking to add your tests to a CI tools like Jenkins. You’re going to want to take advantage of the additional features.

Next Lesson ➔

Maven Surefire Plugin Docs

Richard Bradshaw's photo

Richard Bradshaw


Software Tester, speaker and trainer at Friendly Testing. BossBoss at Ministry of Testing. Whiteboard Testing creator. Striving to improve the testing craft.