java: OutOfMemoryError: insufficient memory while running JUnits in Idea

前端 未结 5 1583
一整个雨季
一整个雨季 2021-01-07 23:20

I am trying to run JUnits from my IntelliJ Idea When I try to run the Test.java file it gives me an error saying that

java: OutOfMemoryError: insuffic

相关标签:
5条回答
  • 2021-01-07 23:48

    Idea runs unit tests in a separate java process.

    You need to use

    Run -> Edit Configurations...
    

    and add your -XmxNNNm to VM Options.

    For example:

    -ea -Xmx1024m
    

    The "-ea" means "enable assertions".

    If your unit test(s) can't run in a 1GB of memory then it's possible that you have a memory leak.

    0 讨论(0)
  • As this OOM happened during compilation, you need to increase compile VM:

    0 讨论(0)
  • 2021-01-07 23:52

    In my case, my SpringBootTest configuration has Build (whole project) gradle task in "Before launch". So that's my omission. Eliminating that and issue's gone away.

    Or Settings -> Compiler : increase build heap size

    0 讨论(0)
  • 2021-01-08 00:02

    To increase heap size is one option. For me (using subversion for source version control) it was even easier to unload some of the modules which I had checked out and where not directly used for the test. This will also speed up the build process for future tests.

    Right click on any module in the project-area of IntelliJ -> Load/Unload modudules -> Choose one/some bigger module and move to the "unload" area.

    0 讨论(0)
  • 2021-01-08 00:09

    Based on your log the problem is in compiler heap space.

    Go to

    Settings -> Compiler -> Build process heap size (MB)
    

    and increase that value.

    0 讨论(0)
提交回复
热议问题