Conversation
|
@Kolos65 Same with this. If the linux stuff now passes, feel free to fix any remaining commit message issues and tweak the code if you see any issues. |
|
Thanks for this as well @Archdoog! I like the idea of the referenced ContainerTrait, but I'm not entirely sure about translating that to Matcher. I think the important question is this: Are matchers more often unique per test case / test suite or are they more global across a project? I think most of the time you would want your custom matchers to be available everywhere across the test suite and require a single setup point (just like a conformance to Equatable). This design was inspired from SwiftyMocky where it proved to be robust. |
That's a fair assessment and historically would've been totally correct. I think this is less of a feature question and more of a stability requirement for modern swift (modern concurrency and swift testing). Ironically, I actually have a single custom matcher setup function that's used for my entire testing environment. This was the end result of a few days debugging random CI crashes caused by the Matcher fatalError for missing type. In summary, with Swift Testing's concurrency, this is basically a requirement to ensure reliably isolated tests. Without it, anyone using Mockable with swift testing and custom matcher calls will be stuck with singleton races causing flaky and inconsistent test crashes. Deeper diveThere are multiple reasons for and notes about this:
Before this, I was able to run my ~1500 unit test suite on repeat on my MacBook Pro thousands of times. Failure would occur in 1 or 2 tests occasionally. However, in a resource constrained CI environment, I was getting 20-50 tests every run that would crash and kill the entire run. Each time they were different tests and the missing matched type was either one of my own or one of the defaults. Lastly, there's not really a drawback to this solution. As an aside, it looks like SwiftMocky might encounter similar issues 😅. Looks like they have some old issues about parallelization (e.g. MakeAWishFoundation/SwiftyMocky#229). These seem likely to be a much larger problem as more teams realize the other benefits of swift testing (one of which is massive CI speed improvements). Happy to answer any more questions here. I've actually got a keynote file about modern concurrency that I need to reformat and publish somewhere. There are so many subtle difference between modern concurrency and the old swift 5 stuff that make it clear why some of these new solutions exist and the problem(s) they solve. |
|
One final note, the unit test that verifies this is making use of an anti-pattern just to verify that |
Inspired by: https://github.com/hmlongco/Factory/blob/bcca76f9243ace59477c8d077d25a97795eab5c4/Sources/FactoryTesting/ContainerTrait.swift