I'm trying to create some unit tests using the new Swift Testing framework. I've created an empty test using the Xcode template file generator.
import Testing
//@testable import MyApp
struct Test {
@Test func EmptyTest() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
}
}
If I leave the line which imports my project (MyApp) commented out. The test runs and finishes successfully. If I simply uncomment this line so that my it imports my project (and I can actually write something to test my code), it refuses to build. Here is a sampling of the errors generated:
Type 'Testing' has no member '__requiringTry'
Type 'Testing' has no member '__requiringAwait'
'__TestContainer' is not a member type of class 'MyApp.Testing'
'Test' is not a member type of class 'MyApp.Testing'
The origin of this project dates back to 2016 if that makes any difference. However, I'm now building it on the latest Xcode(16) targeting iOS 18. Can anyone point me in the right direction? Since this framework is quite new, there isn't a lot of help available out there.
These two error messages
'__TestContainer' is not a member type of class 'MyApp.Testing'
'Test' is not a member type of class 'MyApp.Testing'
suggests that there is a class called Testing
in the module MyApp
.
The @Test
macro generates code that says Testing.__TestContainer
and Testing.Test
. Normally, Testing
would refer to the Swift Testing module, which declares types called __TestContainer
, Test
, and many others.
However, since MyApp
also has a Testing
class, Testing
in Testing.__TestContainer
refers to your class.
So you should rename the Testing
class to something else to resolve this name conflict.