-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setUp and setUpBeforeClass run before filters/groups applied #261
Comments
Am I the only person who thinks this is an issue? Certainly all other developers I work with agree that this appears to be totally unexpected and unnecessary behaviour? I am totally willing to fix this myself and contribute the patch but I can't believe no one else could care about something that, in my experience, massively impacts on the usability of PHPUnit to construct and run large test suites. Perhaps I'm missing something here. Please, anyone, share your thoughts on why this is written as it is and whether there is any reason not to simple move the setup calls to be after the filtering check. |
I'd say this is a big issue. This bit me recently when a data provider relied on functionality that wasn't available. Even though the tests that used the provider had been excluded with groups the provider was still being invoked. |
I agree that this seems to be unintentional. I can think of no reason to run those methods if none of the tests in the test case will be run. |
Just ran into this problem as well. Any news on this? |
Hi, the workaround is to add a static variable + a check in setup() :
And then:
|
@tarjei not sure how that helps? The problem is not that the constructor runs multiple times. Given PHPunit's runner that is not surprising in some circumstances. The issue I'm complaining about is that the setup is run at all in the case where you are not actually running any tests from the class in question. In my case I don't see multiple |
Yes is this an issue related to #10. With the current way of running the tests the filtering isn't applied before TestSuite.php executes the setup. With a big test suite and a phpunit.xml what should work is using directory based filtering with The only idea i have to work around this is to lazy initialize your stuff in the first call to I'm quite sure that this will be taken care of by #10 but if you need this sooner and the patch is rather small/manageable this might get into PHPUnit 3.7 (Not 3.6.x as it breaks bc). The workaround by tarjei works as the code is in |
Here is a post on SO that may help others who are still having problems with the filtering not preventing the fixtures from being run: PHPUnit filtering not working with setUpBeforeClass() and tearDownAfterClass() I'm sorry if there is a better way that I have just missed in the docs. |
…int evaluation * Add test to reproduce Issue sebastianbergmann#261 * Fix Issue sebastianbergmann#261
I'm not sure if this is intentional but I don't see the rationale if it is. I also couldn't find documentation or other issues to suggest this is a known/discussed topic.
Basically: I user the
filter
and/orgroups
options to limit the tests run by the test runner as documented.I've realised though that since the code that calls
setUp()
andsetUpBeforeClass()
methods is before the filtering is applied, (code link) every test in my suite will havesetUp()
run and every test case will havesetUpBeforeClass()
. This means any expensive setup work done is run for the whole suite even when the tests that require the work are not being run.I'm aware that you can specify specific test case classes to run and thus avoid this but in a very large test suite, the flexibility of
filter
andgroups
is very useful. It comes with a huge cost of running potentially thousands of setup routines though just to run a single simple test.If this is intentional behaviour, it would be great to understand the rationale behind it. If not, it appears a relatively simple fix and I am can fork and make the required changes.
Thanks for you time and effort on this PHPUnit!
The text was updated successfully, but these errors were encountered: