简体   繁体   中英

Not able to use objective-C class in swift unit tests

I want to use objective C class in my swift tests.

  • My project is initially set up in objective c.
  • I have bridging header set up already working for my project.
  • I have import statement already in place in bridging header for the file, which I want to use in tests.
  • Search paths for test target are also set to same bridging header, although I've tried using separate bridging headers also.
  • I use cocoa pods so have a xcworkspace file.
  • Pod file has inherit search path included for tests, though I am not using pod frameworks in tests.

I get 'Use of undeclared type 'SySearchProductRequest'' error while trying to use the class. SySearchProductRequest is the objc class I want to use.

I am using @testable import Mymodulename to import my module which has this class, in tests.

I am stuck with an approach of writing objc test cases, which I don't want to do. Is there a way or is there something I am doing wrong or missing to make this work.

Just check if your class is added to Test Targets in Target Membership in File Inspector Example Screenshot . and Then Build the project again . Hope It removes the error .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM