Running Isolated Tests Without Relying on Terminal? IntelliJ IDEA

535 views Asked by At

I understand that I should use the sure-fire plugin for unit tests, and failsafe for integration. I can run unit tests with mvn test and integration tests with mvn verify but this annoys me for 2 reasons:

  1. I'd prefer to be able to select any test class (or method in that class) and run it individually by a simple click, rather than typing it into terminal every time.

  2. The terminal returns the test results in ugly black/white paragraphs, requiring me to sift through them. I'd much prefer to have the results returned in a visually organized manner, similar to if I right-clicked on the test class in IntelliJ and click 'RunDemoTest`. This produces:

enter image description here

I find the error results much easier to sift through, for example it shows red/green @Test results on the left, and on the right it cleanly organizes the error into

Expected : 3

Actual :1

I'm sure there are advantages to using terminal for automated test runs later into production, but during development I don't find the terminal conducive to my tinkering.

How do I benefit from IntelliJ's visual feedback of test results, while simultaneously ensuring unit & integration tests are run separately, and preserving my freedom to pick and choose which test classes and test methods I can run at any time?

I'm assuming I can't have my cake and eat it too. Please explain.

1

There are 1 answers

1
JimHawkins On BEST ANSWER

If you are using the IntelliJ view "Maven Projects" you can very easy toggle on/off the exection of maven integrated tests.
enter image description here

Via "Run/Debug Configurations" you can create test executions that match your reqirement for a comfortable UI.

enter image description here

After these steps, there is a new entry in the drop down list "Run/Debug configurations". When you start the new JUnit Test configuration, the defined tests are executed and the results are presented exactly in the same manner as the screenshot in your question.

The options in my second screenshot allow a very flexible definition of the scope. You don't have go to every java file and click on the green arrows in the editor view.

enter image description here

This configuration isn't related to any maven configuration, and you can use them at any time in your coding process.