开发者

How much memory for unit test suite is ok?

I have ~700 tests with ~1500 assertions, tests are running on sqlite on RAM drive. I run this using phpunit /dir/name, without any additional suite setup.

The tests are written well (I hope so), the app and each one test runs fast and the memory usage for each one is not big (never bigger than 10M).

Everything is ok once the tests are running separated. But when I run all the tests togeth开发者_开发技巧er, PHPUnit reports memory usage about 450MB.

  • Is 500M ok? Shall I update the memory_limit to 700MB to be safe?
  • How to avoid such a memory usage?

I understand that the answer is depends on the app, but I wonder which memory level can tests for a medium level app reach.

Update:

We are using transactions and rollback db changes in tearDown()


PHPUnit instantiates a test case for each test method and each argument array for each data provider before running any tests. To boot, any exception and assertion failure has a reference to the instance that threw it. This makes it very important to unset any instance variables you assigned to the test in tearDown() as MasterCassim said.

But it mainly means that you have to accept a growing memory requirement as the number of tests increase. If you generate code coverage as well this jumps considerably. Our main website project runs with a limit of 2GB.

You can run the tests in separate processes, but you'll pay a high price in increased run times.

Note: Issue #10 is supposed to address this, but I don't know what the status of it is in 3.6.


If you run the tests together you have to use the tearDown() method to "free" memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜