How to create application tests in Cocoa Touch Unit test suite with Xcode 4?

I created an Xcode 4 project with the Cocoa Touch Unit Testing Bundle. I can successfully create and run logic tests. However, I'm not sure how to create a test as an application test that runs on an iOS device and uses UIKit. When I create a test that uses UIKit and try running the bundled tests on the device, Xcode 4 will open a dialog box that says:

Logical testing not available

Logical testing on iOS devices is not supported. You can run logic tests on a simulator.

I tried running the test on a simulator, but of course it was not able to make UIKit calls.

Does anyone know how to create and run application tests on iOS devices using Xcode 4 and Cocoa Touch Unit Testing Bundle?

EDIT: In case this helps, here is the test code:

@implementation TinyWordsTests - (void)setUp { [super setUp]; CC_DIRECTOR_INIT(); } - (void)tearDown { CC_DIRECTOR_END(); [super tearDown]; } - (void)testExample { CCScene *scene = [TWOHelloWorldLayer scene]; STAssertNotNil(scene, @"Scene must not be nil."); } @end 

and the resulting stack trace from gdb when the test runs in the simulator:

 (gdb) bt #0 0x00464781 in __HALT () #1 0x003af8ed in _CFRuntimeCreateInstance () #2 0x00da81ea in GSFontCreateWithName () #3 0x038f55eb in UINewFont () #4 0x038f56bd in +[UIFont fontWithName:size:traits:] () #5 0x038f507d in +[UIFont fontWithName:size:] () #6 0x01a49205 in -[CCTexture2D(Text) initWithString:fontName:fontSize:] (self=0x197f9f0, _cmd=0xe10840, string=0x1a9c900, name=0x1a9c8f0, size=64) at CCTexture2D.m:487 #7 0x01a2d897 in -[CCLabelTTF setString:] (self=0x1981d70, _cmd=0x156e07, str=0x1a9c900) at CCLabelTTF.m:95 #8 0x01a2dc9d in -[CCLabelTTF initWithString:fontName:fontSize:] (self=0x1981d70, _cmd=0xe10840, str=0x1a9c900, name=0x1a9c8f0, size=64) at CCLabelTTF.m:79 #9 0x01a2da9a in +[CCLabelTTF labelWithString:fontName:fontSize:] (self=0x1a9b53c, _cmd=0xe0ddc0, string=0x1a9c900, name=0x1a9c8f0, size=64) at CCLabelTTF.m:53 #10 0x01a01b10 in -[TWOHelloWorldLayer init] (self=0x197ee40, _cmd=0x2c7c) at TWOHelloWorldLayer.m:39 #11 0x01a341bb in +[CCNode node] (self=0x1a99ee4, _cmd=0x3baad59) at CCNode.m:231 #12 0x01a01a80 in +[TWOHelloWorldLayer scene] (self=0x1a99ee4, _cmd=0xe00fa0) at TWOHelloWorldLayer.m:22 #13 0x01a5d430 in -[TinyWordsTests testExample] (self=0x197e490, _cmd=0xe59dd0) at TinyWordsTests.m:30 #14 0x00410c7d in __invoking___ () #15 0x00410b51 in -[NSInvocation invoke] () #16 0x201043d2 in -[SenTestCase invokeTest] () #17 0x20104aa7 in -[SenTestCase performTest:] () #18 0x201041d3 in -[SenTest run] () #19 0x20106eda in -[SenTestSuite performTest:] () #20 0x201041d3 in -[SenTest run] () #21 0x20106eda in -[SenTestSuite performTest:] () #22 0x201041d3 in -[SenTest run] () #23 0x201067a4 in +[SenTestProbe runTests:] () #24 0x000023c7 in ?? () #25 0x000025f2 in ?? () #26 0x0000209a in ?? () #27 0x00002049 in ?? () 
+6
source share
2 answers

Unfortunately, iOS testing is a mess with official tools. There are two types of unit tests. Logical tests that have no user interfaces and work in the simulator. Application tests that can implement and manipulate the user interface, but only work on the device.

It looks like you wrote logic tests that use the user interface. You want to create application tests and run them on the device. To do this, you must follow http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html and create an independent launch object on the device that includes the AppTest target.

But, just on the sidelines, this is rather tedious, since you need to add all the code for the tests and dependencies to each target and target application. You should also place logic tests only in the target logic tests and applications in the target test application.

+2
source

For this to work correctly, you need to go to the test package build settings and set Test Host to $(BUNDLE_LOADER) .

Also, make sure that the Bundle Loader parameter is set to $(BUILT_PRODUCTS_DIR)/yourAppName.app/yourAppName in the package build settings.

+8
source

Source: https://habr.com/ru/post/885586/


All Articles