IntelIj IDEA运行JUnit Test OutOfMemoryError

时间:2022-05-04
本文章向大家介绍IntelIj IDEA运行JUnit Test OutOfMemoryError,主要内容包括修改build内存、修改运行时内存、来源、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

好久没看到OutOfMemoryError这种错误了,今天跑测试的时候发现总是报错。针对IDEA需要修改几个配置。

JUnit Test在运行前,IDEA会build整个项目,这个是喜欢eclipse的人最讨厌的地方,因为即便是别的不相干的类没配置好,我的Test也不能跑。我的错误正好是build的时候出现内存不够的。

修改build内存

位置Settings -> Compiler -> Build process heap size (MB), 原来默认是800m,修改2048M后,错误消失。

修改运行时内存

针对当前运行的Test,你需要配置运行内存。

Run -> Edit Configurations...

设置 -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.

来源

stack overflow;

https://stackoverflow.com/questions/24323628/java-outofmemoryerror-insufficient-memory-while-running-junits-in-idea