FUnit icon indicating copy to clipboard operation
FUnit copied to clipboard

FUnit::setup() and bootstrap files

Open henderjon opened this issue 11 years ago • 3 comments

This is more a point of clarification. In the docs you say that FUnit::setup() "Register['s] a function to run at the start of each test."

Does that mean that it's executed before EVERY single closure (having been set by FUnit::test())? Or is it only run at the beginning of every file of tests?

I ask because I was trying to set up a bootstrap file to setup a few fixtures (specifically a DB connection) that were shared between a few tests (spread across a few files) but each fixture kept coming out null until I moved them from a global bootstrap into each test file. This is probably a 'dark corner' of bin/fu not yet explored?

henderjon avatar Apr 01 '14 18:04 henderjon

FUnit::setup() and FUnit::teardown() are supposed to run before and after each test registered by FUnit::test(), respectively.

You can also use FUnit::before() and FUnit::after()to run things before and after each suite registered with FUnit::suite()

the setups and teardowns are now tied to suites. A suite is automatically created if you don't initialize one, and everything is attached to that. When FUnit::run() is called, the current suite's tests are run, the results are saved, and FUnit::$current_suite_name = null is reset to null.

I would probably try running fu with --debug to see when suites get created and what tests are being attached to what suites.

funkatron avatar Apr 01 '14 18:04 funkatron

Good call.

It looks like each individual file (I'm using the new '-r' flag) is treated as an individual suite. While this complicates the idea of a global bootstrap, I don't mind. There's probably a better way than what I'm doing to incorporate a global setup, but I'm not convinced it's necessary and given the choice (at this time) I think I prefer the current behavior of each included file being treated as a suite unto itself.

If I have any other thoughts I'll let you know.

Thanks again.

henderjon avatar Apr 01 '14 19:04 henderjon

Perhaps there should be a global set of fixtures? Or maybe that's outside the scope of FUnit… keeping it simple and all. Not sure.

Thank you!

On Tue, Apr 1, 2014 at 3:38 PM, Jon Henderson [email protected]:

Good call.

It looks like each individual file (I'm using the new '-r' flag) is treated as an individual suite. While this complicates the idea of a global bootstrap, I don't mind. There's probably a better way than what I'm doing to incorporate a global setup, but I'm not convinced it's necessary and given the choice (at this time) I think I prefer the current behavior of each included file being treated as a suite unto itself.

If I have any other thoughts I'll let you know.

Thanks again.

— Reply to this email directly or view it on GitHubhttps://github.com/funkatron/FUnit/issues/20#issuecomment-39248895 .

funkatron avatar Apr 01 '14 19:04 funkatron