IntelIj IDEA运行JUnit Test OutOfMemoryError

好久没看到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

posted @ 2018-01-18 10:02  Ryan.Miao  阅读(1758)  评论(0编辑  收藏  举报