cgreen icon indicating copy to clipboard operation
cgreen copied to clipboard

`BeforeOnce()` or similar to run "module" level setup/fixture

Open thoni56 opened this issue 9 years ago • 1 comments

In some cases where creating a fixture might be costly and there are no risk of it being compromised by the tests themselves it is often handy to do a single setup once before all tests.

Such example is the setup of database connections or complex structures. In the docs there is also a (somewhat outdated) discussion that touches on these matters.

A suggestion would then be to introduce a BeforeOnce(context) and of course corresponding AfterOnce(context) in analogy to BeforeEach() and AfterEach().

(I considered BeforeAll() but that seems to be too easy to mis-interpreter as BeforeEach(), other suggestions welcome...)

Such a function should probably be run in the parent so that environment variables can be set to affect the running of testcases. There are a couple of testcases for Cgreen itself that currently relies on a command line with the appropriate variables set, which is not as rubust as I'd like. This is not strictly necessary for this feature to be valuable, but if it were then we could clean up some testcases in Cgreen.

Note that this might not be quite as straight forward as it might seem since interference with legacy setup()-strategy has to be considered.

thoni56 avatar Nov 04 '16 09:11 thoni56

I pulled the original phrasing from the jasmine unit testing framework for JavaScript. if possible, let's stick with that. they chose beforeAll and afterAll.

as far as interference with the old setup() approach, I would advocate for deprecating setup() when this feature is introduced.

matthargett avatar Nov 04 '16 19:11 matthargett