How can I launch OCUnit test on iPhone from Command line - iphone

I want to run unit test on iPhone without using Xcode. Is there any command line utility to run OCunit test on iPhone device.
I also tried fruit-strap but it only launches App not OCtests. "fruitstrap -d path_of_app" this command install app but I did not found any way to install and run octest on iPhone.

Look at the similar issue, I've opened recently: Is there any non-Xcode-based command line testing tool for Objective-C.
There is the answer by #MalteTancred. I am trying to adapt his answer to my project and can say that it is not a very easy task to get the stuff (that Xcode does out of box) to work when made by hands in command line.

Related

How to package a PySide/Phonon app under Mac OSX?

I have a PySide/Phonon app (developed for and working flawlessly on Windows) that I need to "port" to Mac OSX - where I have no development experience whatsoever.
The app works as expected if I just run the Python file - the problems arise when I try to package it (which I need to do) with py2app.
If I leave the resulting .app as is, Phonon doesn't work, because it fails to load the required phonon_backend ; if I add the plugin path to qt.conf, as various sources suggest, Phonon seems to load (that is, I don't get the corresponding error message anymore), but I start getting the "so-and-so library is loaded twice, one will be used, which one is undefined" error, and the app crashes right away.
Finally, if I try to use the macdeploy_qt tool, I receive a message to the effect of "no external framework" and the results are functionally equivalent to what I get without using the tool, except there are a few more plugins in the relevant directory.
Any ideas/pointers/tutorials/etc? I'm using PySide1.1.1 for Qt4.7, by the way, and Python.org python binaries (otherwise py2app can't even start to build a standalone app, it seems).
I suggest you do it like in this tutorial.
Then you just have to add the following line somewhere at the top of your main module:
QApplication.setLibraryPaths([os.path.join(os.environ['_MEIPASS2'], 'qt4_plugins'), os.environ['_MEIPASS2'] ])
For PyInstaller >1.5 the following code should be used instead:
QApplication.setLibraryPaths([os.path.join(sys._MEIPASS, 'qt4_plugins'), sys._MEIPASS])

Code Coverage GCov not working with XCode 4.2 and iOS SDK 5

I've been trying to get GCov working with Xcode 4.2Build 4D199 on Lion with iOS SDK 5.0 to no avail. Has anyone had any luck with this? I'm using Google Tools For Mac for my unit tests and I've linked in libprofile_rt.dylib and added:
"OTHER_CFLAGS[arch=*]" = (
"-ftest-coverage",
"-fprofile-arcs",
"-falign-loops=16",
);
as indicated on the Coverstory page here http://code.google.com/p/coverstory/wiki/UsingCoverstory
But when I find . -name *.gcda" I come up empty. What am I missing?
GCov is no longer supported in XCode 4.2. You'll note that if you go their "man page" for it, XCode 4.2 is not an option in the drop down list. Furthermore, if you look at the compile, it's using "c++", which is linked to llvm-g++-4.2. They now exclusively use the Clang/LLVM tool chain (which in turn often makes use of the gcc tool chain) instead of giving you the option of directly using the gcc tool chain. A consequence of this is that doing code coverage in XCode4 with gcov is no longer directly available. This also can affect compiles using CMake that bypass XCode 4. That first link gives you instructions on how to change your project to use profile_rt instead of gcov.
How to generate coverage test reports (Xcode 4.5 edition)
cd to your Xcode project and type
git clone git#github.com:j4n0/XcodeCoverage.git
cd XcodeCoverage
wget http://downloads.sourceforge.net/ltp/lcov-1.10.tar.gz
tar -zxvf lcov-1.10.tar.gz
Set the following build properties on both your main target and your SentestKit target, but only for the Debug configuration (expand the node, there are Debug and Release entries):
Generate Profiling code Yes
Generate Test Coverage Files Yes
Instrument Program Flow Yes
Install Xcode command line tools: Xcode > Preferences > Downloads > Command Line Tools.
In your main target, add a “Run Script” build phase to execute ./XcodeCoverage/exportenv.sh
Build your application, and run the tests.
Generate the coverage report from the XcodeCoverage typing: ./getcov
Upon completion, the script will launch a browser with the html output.
If reports are not generated try this:
Edit the plist of your application and add the following:
<key>UIApplicationExitsOnSuspend</key>
<true/>
Then run your application and press Home. This will quit cleanly and generate the gcda files.
If it still doesn't work, try using the iPad simulator instead.
For more tips and tricks check the talk Code Coverage on iOS by Richard Buckle.

iPhone Application crashes in "AdHoc" mode

i got a little application which is working very well with my "debug" configuration on my phone and in simulator.
i created a adhoc provisioning profile, and added a "beta" configuration to it.
trying to launch the application with the ad-hoc configuration crashes my application immediatelly.
the console output is:
Running…
Error launching remote program: failed to get the task for process 2434.
Error launching remote program: failed to get the task for process 2434.
The program being debugged is not being run.
The program being debugged is not being run.
i also created a dist.plsit, unchecked the get-tast-allow and setted this file in my built settings under code signing.
does anyone have an idea?
thanks!
Sometimes when you change lots of things, especially build configs, xcodebuild doesn't seem to figure out which files are stale and links in old stuff that needs to be rebuilt. Try doing a Clean All or just delete your build directory from the project dir. That seems to solve most of these bizarre-ass unexplainable problems for me.
simple thing. i clicked "built and run" instead of "built".
an ad-hoc version cannot be debugged :D

Console and Debugger not working while Unit Testing iPhone in XCode

I am building a logic test suite using Xcode 3.1.4. I am able so far to build the test target and see the results inside de *.m test files as compiler errors (if they fail). The problem is that I can't see any information in the Debugger Console and I can't debug since the debugger does not work either.
1.How can I do to see TestCases ouput on the debugger console?
2.Are there any configuration issues regarding Unit Testing and Debugging test cases?
I would be very greateful if anyone could help me.
Thanks!!
You can setup Google Toolbox for Mac. With it, you will be able to step through your code both on simulator and device.
http://www.grokkingcocoa.com/how_to_debug_iphone_unit_te.html worked great for me, once I unchecked the DYLD_FRAMEWORK_PATH environment variable.

Is there a way to simulate multiple iphones using xcode/iphone sim?

I'm planning out a game that requires multiple users and I was wondering if there's a way to fire up multiple instances of the iPhone Simulator. I didn't see anything in menus or in Google search results, but I just wanted to make sure I wasn't missing anything.
It is possible but only with multiple users.
Read this: http://www.coderebel.com/2010/08/31/iphone_simulator
Assuming you have two projects (P1,P2) which you want to debug simultaneously, do as follows.
Steps to set up:
Create a new user (U2) on your Mac
Give it R/W access to P2, especially to its build folder.
Download the launcher app from the site above and copy it to Applications.
Steps to debug:
Close Xcode and the simulator if running
Launch the iPhone Launcher.app with U1.
Start Xcode with U1, load P1, start debugging.
Launch the iPhone Launcher.app with U2.
Start Xcode with U2, load P2, start debugging.
Unfortunately it's a P.I.T.A. having to change users every now and then but so far I haven't found any better solution. Hope this helps.
There is a way to do this easily without using multiple users. Keep in mind you will not be connected to the debugger though. Keep in mind the explanation below is for XCode 6+. You can skip this explanation and just scroll down to the wrapping-it-up section below.
From an answer here we can see that you can launch any simulator from command line:
open -a "iOS Simulator" --args -CurrentDeviceUDID
You can find the deviceID (as well as all your simulators) by running the xcrun simctl list command on console. It will generate a list like this. The device ID is the code in braces:
== Runtimes ==
iOS 8.3 (8.3 - 12F69) (com.apple.CoreSimulator.SimRuntime.iOS-8-3)
== Devices ==
-- iOS 8.3 --
iPhone 4s (99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8) (Shutdown)
iPhone 5 (K262AF11-ADD2-4FDA-ACBA-8C80DD9D4AA1) (Shutdown)
iPhone 5s (337KDC51-0A4B-47DB-8966-83562FD92C93) (Shutdown)
iPhone 6 Plus (9GK714E2-F713-4F98-A96E-C72ACD6571A8) (Shutdown)
-- iOS 8.2 --
etc continued....
Therefore to run the simulator using above as example, run this command on console:
open -n /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/ --args -CurrentDeviceUDID '99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8'
We use the -n flag instead because the -a flag specifies the application to use for opening the file, while the -n flag opens a new instance of the application(s) even if one is already running. Use the man open command to know all this stuff.
Also make sure you have the correct path for your simulator.
One more thing to note, if you run the simulator like this, chances are that you have limited simulators. And since its limited, you might want to launch it without interrupting one that's already on the screen. We can solve this from this answer here where he shows you how to create a new simulator and delete one.
So wrapping it all up, here's what you do to launch them.
A) First Create a simulator before launching it.
Usage: simctl create "name" "device type id" "runtime id"
xcrun simctl create "mynewsimulator" "iPhone 6" "com.apple.CoreSimulator.SimRuntime.iOS-8-3"
You will find the runtime id from the command xcrun simctl list command I ran above. After running the above command, the deviceID will be printed on the console screen. Take note of it as you will need as the last argument to launch the simulator shown below. Let's assume this ID was 99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8
B) launch it
open -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/ --args -CurrentDeviceUDID '99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8'
C) delete it once you're finished with your simulator
xcrun simctl delete 99Z06AC6-A2D6-46E7-B4F7-BA4F5F3F39C8
All this can be placed in a single .sh file for easy running.
Please note to put wait or sleep commands after each command if you decide to put all this into a sh file.
[EDIT 2017]
I see that XCode 9 will now support multiple simulators. Awaiting to see how it will all work.
As near as I can tell, not only can you not have multiple instances of the simulator running, but when time comes for actual device testing you can't have multiple instances of the debugger running either.
This means to do multi-device apps, you'll need to have a single Mac assigned to a single iPhone/touch device (or simulator instance) each running your app.
I've started looking into whether VMWare or Parallels can somehow be brought into this, but there's not much that can be done without hacking the OS.
I suggest filing a feature request with http://bugreporter.apple.com.
Another option (albeit probably overkill) if you have a Mac OS X server license is to virtualize an instance of Mac OS X Server, and run a second simulator in the VM.
Hmm...I don't think you are missing anything here. As far as I know there is no technology within the SDK that is able to emulate multiple devices -- though that would be a useful feature to have. I think your only options would be to get a second iPhone OS device, or get a friend who also has an iPhone OS device to let you use it for testing.
In XCode 4 you can run multiple instances while having both be in debug mode.
What I did was create a duplicate of my target and ran both the original and the duplicate. If you're using the output window you can toggle which output you are looking at.
Follow these steps to test your app.
You have to do one thing for whole process first :
Go to Project - > Edit Project Settings -> tick on option - Build independent targets in parallel.
Debug code that will create your app in simulator For Example your App name is - Instance
Close Simulator
Go to Project->New Target -> Instance2
Add "Bundle display name : Instance2" in Instance2.info.plist file
Set Executable Name : Instance2
Select Instance2 Target -> Go to Project -> Set Active Target -> Instance2
Build with Instance2
Note : Do all carefully otherwise you have to reset your simulator
For Reset Simulator -> Run Simulator -> iPhone Simulator -> Reset Content & Settings...
Now You have two apps in simulator and you can test app on all instance.
Hope it will help you :)
I managed to get it to work combining answer by Ivsty with this one.
Basically, what you do is create two users (A and B), run simulators in each of them, run VNC server on user B, and then connect from user A to access screen B without needing to switch users.
Yes, now it's possible and is also quite easy.
The only thing you need is xctool, the build tools from Facebook and a ruby gem. The ruby gem helps to create/destroy the simulator needed during the test.
You can read the full documentation on this link:
https://github.com/plu/parallel_ios_tests
I'm using this approach and I run my test on 4 iOS simulator on the same time.
Supported from Xcode 9 on.
(Source: WWDC 2017)