-
-
Notifications
You must be signed in to change notification settings - Fork 905
Added a TestState property wrapper, again :D #1233
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
Conversation
It's for use in tests where a property should be reset to either nil or an initial value between tests.
b9e0735 to
fbdda51
Compare
younata
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for re-adding this!
|
@younata when it was removed from Quick, we created separate property wrappers namespaced within QuickSpec and AsyncSpec. Is this approach better? Is it possible to have any errors in the approach in this PR? |
There's no namespacing required with this approach. I don't know enough about how you implemented this to know whether it'll interfere with your approach.
If XCTest ever does run test discovery in parallel, then there's the potential for errors as I don't think it's worth worrying about parallelized test discovery at the moment. I'm more than happy to release this as a beta, if you'd like. Otherwise, I was planning to release it as part of 7.2.0 on Friday morning. |
|
I was worried about parallelized testing but if runnings tests in parallel doesn’t change how currentExampleGroup works, that sounds good. Thanks for your reply. |
|
Yes. That's correct. Edit: The way that XCTest does test parallelization is that each parallelized test runs in a separate process. So there's no chance for both those variables to be non-nil at the same time. |
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [Quick/Quick](https://togithub.com/Quick/Quick) | minor | `from: "7.1.0"` -> `from: "7.2.0"` | --- ### Release Notes <details> <summary>Quick/Quick (Quick/Quick)</summary> ### [`v7.2.0`](https://togithub.com/Quick/Quick/releases/tag/v7.2.0): - TestState property wrapper [Compare Source](https://togithub.com/Quick/Quick/compare/v7.1.0...v7.2.0) ### Highlight You can now use the `@TestState` property wrapper to automatically deconstruct test variables. For example: ```swift describe("using TestState") { @​TestState var subject: SomeObject? } ``` Is functionally equivalent to: ```swift describe("using TestState") { var subject: SomeObject? afterEach { subject = nil } } ``` You can also specify an initial value, and `TestState` will act as an `aroundEach`: setting the wrapped variable to the value, then setting it to nil at test teardown. ```swift describe("using TestState") { @​TestState(1) var value: Int? it("is already configured") { expect(value).to(equal(1)) } } ``` Thanks [@​CraigSiemens](https://togithub.com/CraigSiemens) for their contribution! ### Automated Release Notes #### What's Changed - Added a TestState property wrapper, again :D by [@​CraigSiemens](https://togithub.com/CraigSiemens) in [https://github.com/Quick/Quick/pull/1233](https://togithub.com/Quick/Quick/pull/1233) **Full Changelog**: Quick/Quick@v7.1.0...v7.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41Ny4yIiwidXBkYXRlZEluVmVyIjoiMzYuNTcuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
Adds a
TestStateproperty wrapperTestStateproperty wrapper. #1186The main difference from the original implementation is it tries to detect which "World" is currently running tests, then add's the
afterEach/aroundEachto that world. I'm not 100% sure if that's the right approach or if there's another way to add those to the current world.From the original PR description
Checklist - While not every PR needs it, new features should consider this list: