Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run unit tests in IntelliJ with errors in classes

I am new to using IntelliJ. I have only one grievance and that's the compiler. I prefer the way the Eclipse compiler will compile a project and skip classes with errors in them.

This is particularly a problem for if I want to write a unit test for a method I have to fix all errors in the entire project for running a single unit test!

You might say fix your project but I'm working on a project where people have already committed code with errors in it. How can I get around this, I saw there's an option to use the Eclipse compiler in the settings but this has made no difference/I don't know the argument to skip errors.

like image 547
Luke De Feo Avatar asked Oct 23 '12 13:10

Luke De Feo


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.


2 Answers

This fixed it for me on IntelliJ 14:

  • In Preferences->Build,Exec,Deploy->Compiler->Java Compiler, choose Eclipse compiler. Then check "Proceed on errors", which will appear once you choose the Eclipse compiler.
  • Then in Run->Edit Configurations expand the Defaults section on the left. Choose the configuration for your unit test framework (eg, JUnit or TestNG).
  • Then in the "Before launch" section, remove "Make" and add "Make, no error check"
  • Finally, you may need to delete any existing unit test run configurations so the new launch setting will take effect.
like image 108
colini Avatar answered Sep 30 '22 04:09

colini


Not sure if this will be effective for what you're attempting to do and how your project is structured, but it worked perfectly well for me in my particular case, in that if your class has a main method, you can right click inside of the actual main method code and select "Run 'classname.main()'" from there.

This worked for me, but obviously may not be identical to your situation.

I got this from another answer located here: Intellij IDEA how to run a class not the entire project?

like image 36
Eric McDowell Avatar answered Sep 30 '22 03:09

Eric McDowell