Implementing Unit Testing with iOS

妖精的绣舞 提交于 2019-11-27 17:20:41

Double click 'Run script' under 'Targets'/'Your script target name' then type

# Run the unit tests in this test bundle. 
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" 1> /tmp/RunUnitTests.out

Basically you need to append

1> /tmp/RunUnitTests.out

to what is already there

Have you tried to set the build configuration to "Debug" for the test case ?

i did that, as shown at http://nothing2fancy.com/2009/08/04/failed-tests-for-architecture-i386-gc-off/ and it worked

Joe Yang

try to check this issue SenTestCase in Xcode 3.2 and XCBuildLogCommandInvocationSection Errors

the workaround in that question work for me.

Menu: Project --> New Build Phase --> New RunScript Build Phase --> Paste the following into the empty text area:

"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" 1> /tmp/RunUnitTests.out

Now try to build and you should get an error on failed unit tests.

I don't know it a right way or not, but it's work for me.

In General Tab of info Test Case, I add my main application executable target as a direct dependency.

And no error for ‘i386′ (GC OFF)”.

Good luck.

When you create your firt test case classes, make sure the Target is set to your UnitTest target, not your application target.

If you forget to do this when you create the class, you can "Get Info" on the existing class, and set the target there....

OK, never played with unit tests in XCode (of course I liked JUnit in good old java times). So it is just a trial: What compiler are you using, GCC or LLVM? Maybe GCC is the better choice to be on the safe side.

Do you have the same behaviour when "Build Active Architecture Only" in Project settings is enabled? This switch removes duplicate error messages when building for armv6 and armv7, maybe it's related.

Please have a look at apple's latest sample. When you download the code there is a read me file in which its clearly written:

———————————————————————————————————————————————————————————————————————————————
Running Logic Tests
To run the logic tests:
1. Choose Project > Set Active Target > CalculatorTests.
2. Choose Project > Set Active SDK > Simulator.
3. Choose Build > Build. Xcode runs the test cases implemented in
   the CalculatorTests.m file.
4. Choose Build > Build Results to open the Build Results window, containing
   the tests results. You may have to click the Show Transcript button (the
   third button on the bottom-left corner of the build results list) to view
   the build transcript.

The logic-tests results look similar to this:

   PhaseScriptExecution <project_directory>/build/iPhoneUnitTests.build/Debug-iphonesimulator/CalculatorTests.build/Script-17AA84010F99894F00167681.sh
       cd <project_directory>
       /bin/sh -c <project_directory>/build/iPhoneUnitTests.build/Debug-iphonesimulator/CalculatorTests.build/Script-17AA84010F99894F00167681.sh
   /Developer/Tools/RunPlatformUnitTests.include:364: note: Started tests for architectures 'i386'
   /Developer/Tools/RunPlatformUnitTests.include:371: note: Running tests for architecture 'i386' (GC OFF)
   objc[1222]: GC: forcing GC OFF because OBJC_DISABLE_GC is set
   objc[1222]: GC: forcing GC OFF because OBJC_DISABLE_GC is set
   Test Suite '<project_directory>/build/Debug-iphonesimulator/CalculatorTests.octest(Tests)' started at 2009-05-19 16:55:28 -0700
   Test Suite 'CalculatorTests' started at 2009-05-19 16:55:28 -0700
   <time> otest[1222:80f] -[CalculatorTests testAddition] setUp
   <time> otest[1222:80f] -[CalculatorTests testAddition] start
   <time> otest[1222:80f] -[CalculatorTests testAddition] end
   <time> otest[1222:80f] -[CalculatorTests testAddition] tearDown
   Test Case '-[CalculatorTests testAddition]' passed (0.007 seconds).
   <time> otest[1222:80f] -[CalculatorTests testDivision] setUp
   <time> otest[1222:80f] -[CalculatorTests testDivision] start
   <time> otest[1222:80f] -[CalculatorTests testDivision] end
   <time> otest[1222:80f] -[CalculatorTests testDivision] tearDown
   Test Case '-[CalculatorTests testDivision]' passed (0.003 seconds).
   <time> otest[1222:80f] -[CalculatorTests testInputException] setUp
   <time> otest[1222:80f] -[CalculatorTests testInputException] start
   <time> otest[1222:80f] -[CalculatorTests testInputException] end
   <time> otest[1222:80f] -[CalculatorTests testInputException] tearDown
   ...
   Test Case '-[CalculatorTests testSubtractionNegativeResult]' passed (0.002 seconds).
   Test Suite 'CalculatorTests' finished at 2009-05-19 16:55:28 -0700.
   Executed 6 tests, with 0 failures (0 unexpected) in 0.021 (0.022) seconds

   Test Suite '<project_directory>/build/Debug-iphonesimulator/CalculatorTests.octest(Tests)' finished at 2009-05-19 16:55:28 -0700.
   Executed 6 tests, with 0 failures (0 unexpected) in 0.021 (0.024) seconds

   /Developer/Tools/RunPlatformUnitTests.include:388: note: Passed tests for architecture 'i386' (GC OFF)
   /Developer/Tools/RunPlatformUnitTests.include:399: note: Completed tests for architectures 'i386'


Remember that logic tests are executed as part of the build process to provide
you with build errors for failed unit tests. Logic unit-test bundles are not
intented to run in iPhone Simulator or a device.

———————————————————————————————————————————————————————————————————————————————

Hence there is some change in the sentesting kit. I don't think it would be worth for filing a bug.

That is the expected behavior. The build will fail if one of the tests fail and the build will succeed if all the tests pass.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!