How can i add SenTestCase to a cordova or phonegap project?

354 Views Asked by At

when I try to add a test target in an ios project generated via phonegap I get a linker error. It seems like the cordova project inside my project is not able to be found (i think) and so it is throwing an error when i run tests.

I have spent a while searching and no one has this error, is it even possible to create native unit tests for cordova projects? - just to clarify i am using some native code for cookies and want to unit test it.

The error is:

Undefined symbols for architecture i386:
"_CGRectZero", referenced from:
  +[CDVUserAgentUtil originalUserAgent] in libCordova.a(CDVUserAgentUtil.o)
"_OBJC_CLASS_$_ALAssetsLibrary", referenced from:
  objc-class-ref in libCordova.a(CDVURLProtocol.o)
"_OBJC_CLASS_$_CLLocation", referenced from:
  l_OBJC_$_CATEGORY_CLLocation_$_JSONMethods in libCordova.a(CDVShared.o)
"_UTTypeCopyPreferredTagWithClass", referenced from:
  ___30-[CDVURLProtocol startLoading]_block_invoke in libCordova.a(CDVURLProtocol.o)
"_kUTTagClassMIMEType", referenced from:
  ___30-[CDVURLProtocol startLoading]_block_invoke in libCordova.a(CDVURLProtocol.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any help would be awesome!!!! Thanks.

1

There are 1 best solutions below

0
On

Basically, Cordova is relying on Apple frameworks (which are linked at run-time). These frameworks are not packed inside the Cordova project inside phonegap.

It will work, what you need to do is add the relevant Apple frameworks to your project. For example, one of the undefined symbols is "_OBJC_CLASS_$_ALAssetsLibrary", this is an object inside AssetsLibrary.framework. So, add this framework to your project (and make sure that it is linked to your app target).

For each of these undefined symbols, just Google/Bing the part of the symbol that seems relevant (usually the part after the initial underscore or after _OBJC_CLASS_$_) and see what framework the symbol is a part of, then add that framework to your project.

Note in the example below how IOBluetooth.framework and Cocoa.framework are linked with MyTestApp:

enter image description here