Search code examples
javaintellij-ideajunitjunit4

Configuration required to run JUnit in IntelliJ Idea while ignoring compilation error in an unrelated class?


I have been facing issues since very long about running the JUnit in IntelliJ Idea, since there are compilation issue here and there due to some missing jar, or dependency which I should not be bothering about while writing a Junit or testing an existing one.

I have been working with the follwing version of IntelliJ

IntelliJ IDEA 2022.2.5 (Community Edition) Build #IC-222.4554.10, built on March 15, 2023 Runtime version: 17.0.6+7-b469.82 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

I have already tried the existing proposed solution but it didn't worked for me Run JUnit in IntelliJ while ignoring compilation error in an unrelated class?


Solution

  • Apart from adding Before launch: "Build, no error check" in the test configuration, just exclude the modules which you want to avoid for compilation while executing your Junit tests

    You can navigate it through Files > Setting > Build, execution, Deployment > Compiler > Excludes and just add the modules you want to exclude

    But make sure, you re-compile the test file everytime after you make the changes, otherwise it won't run with the latest changes