Unit testing packages in Concrete5

Has anyone successfully been able to write unit tests for their packages using something like PHPUnit? I'm trying it out, but running into issues where Concrete isn't loaded during test time, so tests fail because they are using parts of the Concrete source. For instance, something like this will fail:
Loader::model('people', 'my package');

PHPUnit has no clue what "Loader" is. Is there a file(s) I can include to load up Concrete in my tests?

View Replies:
JohntheFish replied on at Permalink Reply
There was some discussion on this way back.

My conclusion is that its practical for self contained classes, but as soon as a class starts interacting with the database or the core it becomes messy. You end up re-factoring a class to enable such interactions to be stubbed or otherwise intercepted by the test.

I am usually a big advocate of self contained unit tests. But in the case of c5 development, I have found they end up testing the part of my code where the bugs are less likely to be and that integration testing is where I discover something useful in how my code interacts with the database and core. So I often develop code with switch-able traces and logging, so I can monitor what it is doing inside while interacting with the system.

Essentially, I take this:

And wrap it in a php equivalent of this:

And enable the whole lot through a single flag that is on during development and testing and off when released.