Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run JUnit in IntelliJ while ignoring compilation error in an unrelated class?

Tags:

When running a JUnit test case in IntelliJ it opens up the Make console and shows complication errors in an unrelated class.

  1. Can I run the test case ignoring these errors?

  2. Is there a way to make it not compile the entire project when running the test cases but only those class files required by the test case?

like image 281
Kshitiz Sharma Avatar asked Apr 09 '15 10:04

Kshitiz Sharma


People also ask

How do you run a single class ignore compilation error in another class?

Select the 'Main' class in the project view, go-to Run --> Edit Configurations --> Before Launch and in Before Launch click + and select Build, no error check or click '-' take-out(delete) any setting in there --> Click Ok.

How do I fix a compilation error in IntelliJ?

Invalidate Caches/Restart. Delete user config. Create a new project (trying to see if my current project files somehow all got messed up, but the problems persist even with new projects) Uninstall + Reinstall.

How do I exclude test classes in IntelliJ?

To exclude let's say "integration-test", you just need to specify as tags: ! integration-test , and IntelliJ will run all your JUnit5 tests except the ones tagged with integration-test . Take a look at this answer for details (including screenshot).


1 Answers

Yes you can.

You can disable the Make before Run.

(The following is written for IntelliJ 14, different versions might have slightly different layouts, but as far as I can remember these options have been the same for a while)

For a single test

  • Go to "Run" - "Edit Configurations..."
  • Select the configuration of your test case
  • In the tab named "Configuration" there is a List "Before Launch" with one entry "Make". Remove that entry.
  • Confirm with "OK"

For all tests:

If you want to remove this by default for all new test configurations (which might not be a terribly good idea, since then you got to allways build manually when running tests)

  • Go to "Run" - "Edit Configurations..."
  • Select "Defaults" in the Tree
  • Select your Testframework (Junit or TestNG most probably)
  • In the tab named "Configuration" there is a List "Before Launch" with one entry "Make". Remove that entry.
  • Confirm with "OK"
like image 184
Chrstian Beutenmueller Avatar answered Oct 06 '22 02:10

Chrstian Beutenmueller