I've created a basic unit test suite in PHP. It shows whether or not a test passed and the time it took to execute the test. It works great, but I've run into a problem and I'm not sure how to address it. Each initial unit test of each unit test class always appears to take more time to execute than the others in that class, usually by a significant factor.
As an example:
TestClass1
- Test1.1 (0.042395)
- Test1.2 (0.000392)
- Test1.3 (0.000325)
- Test1.4 (0.000645)
TestClass2
- Test2.1 (0.042395)
- Test2.2 (0.000392)
- Test2.3 (0.000325)
- Test2.4 (0.000645)
I'm assuming that the initial test time is also factoring in the loading of resources, but I can't seem to make the first test consistent with the other times. Each test has setUp and tearDown methods that are run. I've also tried repeating the exact same test under a different name and it runs in the expected shorter time, so the first test always has some sort of overhead.
PHP doesn't have any sort of unloadClass or unloadFile function, so I'm not sure if I can recreate a consistent test environment for each test if the first test has the overhead of loading resources into the memory. I've tried preloading files and an initial class instantiation, but neither seems to make an impact.
Are there other possibilities that I might be missing that could be affecting the initial test time? What is the proper way to address this?
Note: I'm aware of existing PHP unit testing frameworks, but I'm trying to do something a little different, so please don't say, "Just use PHPUnit", as it's not helpful in helping me solve this issue.