I write unit tests for a project (written in PHP using PHPUnit) that have their entire environment (loaded components, events, configuration, cache, single individuals, etc.) stored in an object that all components use to interact with each other with a friend (using an intermediary template).
To speed up the execution of unit tests, I separate the environment object and some other objects (for example, in my test case for the view object [as in V from MVC], the view manager object [which acts as a factory for view objects and is responsible for the actual rendering]) among the tests in the same test case (using PHPUnit setUpBeforeClass() and static properties).
Despite the fact that, as far as I know, the objects that I share should not affect the integrity of the tests (in the case of views, for example, the environment object and the view manager object are common, but a separate view object created for each test - which is an object which is actually being tested in a test case), it just feels more and more wrong for me.
I would prefer that each test use a completely isolated environment and in no way could affect other tests in one test case. However, this would make the tests run much slower, and it seems like a great price for not being able to pinpoint the flaw and basically just "feeling wrong."
What do you think? Can you identify any flaws so that I can convince myself that it costs more time to complete? Or am I just reacting, and is all this fine?
source share