Writing unit tests for Bundle project (Mix of Objective C and Swift code)

Currently i am working on bundle project, which has a mix of objective c and swift code in a bundle project. Here is my sample code goes, where I have written a function in Objective C which internally calls swift code for a specific operation. I am successfully able to write and execute a unit test for a objective C functions which contains objective C code only, but, if the same objective C function contains swift code like creating instance for a swift class) where my unit test project fails to compile.


Error:

Undefined symbol: _OBJC_CLASS_$__TtC12SampleBundle11SwiftClass


Example:


SwiftClass.swift

------------------

@objc public class SwiftClass: NSObject {

@objc func doSomething() {

print(" I am in swift ")

}


ObjcClass.m

---------------

@implementation ObjcClass


- (void)doBSomethingobjc {

printf("\n ---------I am in objc--------- \n");


SwiftClass *obj = [SwiftClass alloc]; // Without this unit test runs. //With this i am seeing compilation error, undefined symbol

[obj doSomething];

}

@end


Appreciate your valuable inputs.

Team.. Any suggestion would be helpful on how to solve it.

I'm having a similar issue, and I think it can be replicated with Swift only.

  1. Start a new Swift project as type "Bundle"
  2. Add some code (e.g. a class a method) to be tested
  3. New -> Target -> Unit Test Bundle Note that "target to be tested" cannot be set to your project, see also: https://stackoverflow.com/questions/55277832/xcode-unable-to-add-test-target-to-existing-swift-project-target-to-be-tested
  4. Add a relevant test for your code from step 2 and a @testable import MyBundleName
  5. Undefined symbol errors
Writing unit tests for Bundle project (Mix of Objective C and Swift code)
 
 
Q