Unit tests for Swift and Objective-C files

I'm having trouble setting up unit tests (XCTestCase) for my Xcode project. The project contains Objective-C and Swift files. "Enable testability" and "Define module" set to "YES"

I imported the main project using: @testable import Projectname I created a separate (empty) Bridging header. And make sure that all te files are imported into the target testing group (via Project> Build Phases).

This works fine for all Objective-C classes / files, but not with fast classes with Objective-C functions in it. When I run the test, it fails. And almost all #import lines in the main header of the bridge receive the same warning: "Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)"

I also get a warning for the class I'm trying to import:

 "Undefined symbols for architecture x86_64: "Project.BaseController.__allocating_init () -> Project.BaseController", referenced from: Main_App.ProjectTests.setUp () -> () in ProjectTests.o "type metadata accessor for Flitsmeister.BaseController", referenced from: Main_App.ProjectTests.setUp () -> () in ProjectTests.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)" 

Is it possible to test Swift files with imported Objective-C code? Are there any workarounds?

+7
ios objective-c xcode swift
source share

No one has answered this question yet.

See similar questions:

4
Adding quick unit tests to your Xcode mixed language project

or similar:

1276
How to disable ARC for a single file in a project?
1244
How to sort NSMutableArray with custom objects in it?
1180
How to check if a string contains another string in Objective-C?
928
How do I call Objective-C code from Swift?
251
You cannot use Swift classes inside Objective-C
239
Swift header for Objective-C not created in Xcode 6
98
Xcode MyProjectName-Bridging-Header.h does not exist
87
iOS - File MyProject-Swift.h not found when starting Unit Tests for Swift
31
Testing and using Cocoapods in a Swift project
one
Problem with Linkedin SDK architecture in fast

All Articles