dqhr76378 2014-10-20 10:53
浏览 31
已采纳

降低Laravel的单元测试内存使用率

I have an application written in PHP using the Laravel framework.

And I have a test suite consisting of approximately 200 phpUnit test methods.

The problem I have is that this test suite is taking a painfully long time to run (~10 mins), and has also now started running out of memory on our test server.

I could adjust the max memory in php.ini to solve the latter issue, but that's not really the point: I shouldn't have to -- I don't want to have to allocate 500mb or a gig to a single PHP process. (because, you know, the server might need to do other stuff at the same time)

I've done some investigation, and it seems like the main reason that it's so slow and uses so much RAM is because it sets up a whole new Laravel environment for every test.

That's understandable, but I'm looking for ways to cut it down - either the memory usage or the time taken, or better yet both.

Can anyone suggest ways of streamlining my code or my tests that will help with this?

Thank you.

  • 写回答

1条回答 默认 最新

  • dongxian7194 2014-10-20 11:38
    关注

    Are all of your tests functional, or some of them are unit? If you're unit testing your classes, you don't need to initialize Laravel environment at all, just get an instance of the class involved and set the dependencies.

    Check the "Am I Writing Unit Or Functional Tests?" section of the tutorial on writing Laravel controller tests:

    https://medium.com/laravel-4/laravel-4-controller-testing-48414f4782d0

    So you can extend the Laravel test class when you need the Laravel services, but if you're testing libraries, you can use plain PHPUnit tests.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思