-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Test Ordering and Random Execution #2966
Comments
I think one of the things with testing at the framework level, is that randomising the tests is not an accurate depiction of how the framework should work and be tested. There will be the base layer tests which is testing base functionality at a unity level, but after that testing through the application layer needs to be done in a specific way. |
I sort of agree, but the 'randomising' issue relates mainly to test encapsulation. It may be encapsulation represents too much work and not enough value in this case. Happy for this to be closed if it isn't seen as an issue, I just raised it because I noticed it when I was reacquainting myself with the framework. |
@RobDWaller we should probably fix that. Looking back it’s really a bit of laziness while writing tests to not resetup everything properly on each test that leads to this. |
@l0gicgate I'm sure it wasn't laziness, this sort of thing takes a great deal of work and it's difficult to get it all right immediately. I'd be happy to have a look and try to fix some of these issues. |
@RobDWaller all help is welcome! Feel free to raise a PR if you have time to do it! Thank you for reporting this. |
I've been looking into this and the main thing holding back the test randomization is the global state in static member variables of factory classes here: https://github.com/slimphp/Slim/tree/4.x/Slim/Factory. If we want to keep this architectural choice around, I think we need to find a clean way to rebuild a fresh application with cleared global state in the tests. I don't mind spending some time on this if you believe this is a good solution. |
Hi, I'd like to help with this issue. Currently there are three tests that fail when run in isolation:
For the first two I have bisected to find the commits that broke them and I think I know how to fix them. I'll submit PRs shortly. The last test (
but that's a "solution" based entirely on guesswork (basically disabling / enabling other tests until this one passes). |
Also, it's possible that some tests will still fail when randomized even though they are fixed to run correctly in isolation. But I think getting them to run in isolation is a good first step. |
@pawel-slowik thank you for helping with this. |
As for the last failing test ( As I understand it, the test says: after But the code says: after That's why this test only succeeds when run after another test that disables decorator detection with:
I'm not sure how to proceed further because I don't know which one is the expected / desired behavior. Personally, in this case I find the automatic decorators surprising. When I explicitly say "use my |
Here's a PR that fixes the last test to run correctly in isolation: #3017 As for fully randomizing the tests: this is harder than I thought it'd be due to static properties. For example, if a test executes:
then later the test
will fail, because it relies on Similarily, an earlier invocation of
will cause
to fail, because it relies on a factory being available from What can we do about it?
Thoughts, anyone? |
@pawel-slowik I think this is the best option. I don't really care that tests take longer to run. |
@l0gicgate note that after randomizing the test execution order we'll sometimes see messages emitted by Lines 57 to 60 in 9f6a54f
The messages have no effect on test status. Other than that, I think we're all set. |
@pawel-slowik great! can I close this issue? |
@l0gicgate yes, it's OK to close it. |
Hi, I was just taking a look at the unit tests for Slim 4 and noticed if you set them to run in a random order you generate errors due to state inconsistencies.
Are the tests setup to execute in a defined order?
If you can enable / support random ordering you can implement tools like Infection PHP which will further enhance the improvements made in Slim 4.
These are the settings I added to PHPUnit config:
This is some of the test output generated:
I ask this mainly out of curiosity, I accept there are perfectly legitimate reasons for defined test ordering.
The text was updated successfully, but these errors were encountered: