Closed kelvinharron closed 1 month ago
Did you define the MOCKING flag for your framework? Check out the configuration guide.
Hey @Kolos65 thank you for the swift reply! Yep, with the lates tTuist version, I have defined it as required in the doc. Does this only need to be applied to the target I want to use @Mockable
for? and given that the Test target depends on the actual target, will we inherit it that way?
settings: .settings(
configurations: [
.debug(name: "Debug",
settings: [
"SWIFT_ACTIVE_COMPILATION_CONDITIONS": "$(inherited) MOCKING",
"ENABLE_MODULE_VERIFIER": true
]),
.release(name: "Release",
settings: [
"ENABLE_MODULE_VERIFIER": true
])
]
)
You only need to define it in modules where you want to attach the macro.
Im still suspecting the flag to be the cause of this..
Can you check if it works if you remove @ Mockable from your protocol and copy the contents of the macro expansion next to it (also remove the #if MOCKING)?
When I copy the contents out, it works perfectly, indexing for my test target, and I can access it in my tests.
I suspect that because I am telling tuist to treat "Mockable" as a dynamic framework instead of static, to fix some warnings, this could be upsetting the implementation as I used it as a static framework for a day without any problems. I did get the typing back briefly there before I tried your suggestion of copying the contents, leave it with me and I'll see what I need to do. Thanks Kolos!
I can't reproduce the issue now so I'll close this unless my team members have the same issue and the steps I've walked through do not help.
For anyone with the same issue and using Tuist, I found this setup to help. In your root Tuist/Package.swift file, define Mockable and MockableTest as dynamic frameworks with the following.
#if TUIST
import ProjectDescription
let packageSettings = PackageSettings(
productTypes: [
"Mockable": .framework,
"MockableTest": .framework,
],
)
#endif
Thanks again Kolos! ๐
@Kolos65 To revisit this, I asked a member of the team to check out the branch I've been working on, where Mockable
and its flag are applied to both a framework and an app target, and MockableTest
is applied to both the framework's test target and the app target. While the app and framework targets compile and run correctly, even for testing, we get Xcode errors that prevent our generated mocks from being found even though they're compiled in the macro.
We used your workaround to copy the macro's contents, remove the @Mockable
macro, build the target, and then reset it to use the macro. Voila, all generated Mocks are now accessible and have typing access.
Let me put together a project for you. Tuist may have some quirks, but they could be due to our modular setup. Leave it with me! ๐
"We used your workaround to copy the macro's contents"
That was not a workaround, just an idea to test what the issue might be... If it compiles with the #if MOCKING
flags removed, then the issue must be with the definition of the 'MOCKING' compile condition.
An other way to test this is to define a type like this (next to where your protocols are):
#if MOCKING
public struct TestStruct {
public init() {}
}
#endif
And try to use it in your unit test:
func test() {
let test = TestStruct()
}
I think Xcode 15 and above will even grey out the struct definition if the compile condition is false.
If you put together an example project, I can take a look!
Hey @Kolos65 , apologies for no follow up here. I haven't been able to reproduce this since and until I can with the refactor of the rest of our legacy mocks into Mockable, I'd say it's time to close this. ๐ Thanks.
Hey there. I've recently adopted Mockable as an alternative to Mockolo in our project as we scale up our use of modules. My first impressions are super positive, thank you for sharing this! I have just found an issue I can't reliably get around.
If I have declared a Protocol in my dynamic Framework target called
APIKit
, and I declareMockKeychainServiceType
in my tests target calledAPIKitTests
, I can't get any typing on it even though it actually does compile the mock correctly and I can run my tests against it.and I can see the declaration when expanding the macro, which is correct.
An example of how I use it in the test is as follows.
Do you have any recommendations on how to debug this? I am going to restart my modularisation effort to see if I can source the cause. I've tried clearing derived data and reboot.
Xcode 15.3 macOS 14.4.1 M1 Macbook Pro