App doesn't open when unit tests are running - objective-c

I've written unit testings using xcode 4's built in framework before, and when I run them the process by default seems to be that the app launches and then the tests are run.
I've been moved on to a project that already has tons of unit tests, and I have recently added some of my own. In my unit tests I make a few calls to stuff in [UIApplication sharedInstance]. All of these tests fail because for some reason in this project the app does not open first, so UIApplication sharedInstance returns nil.
I'm assuming that because the default behavior is to have the app open, there has to be an option somewhere that has turned this off. I've been poking around in the scheme editor for a few minutes and can't get anything to make the app run. I've tried clicking the "run" checkbox under the build tab of the unittest scheme and had no success.
Edit: So when comparing a new project to this one, I've noticed that under Build Settings -> Unit Testing -> Test Host there is $(BUNDLE_LOADER) defined. I tried assigning that to the new project, and when I hit done it just magically disappears. No error or explanation of any kind.

I have some strange habit of spending a ton of time trying to figure out a solution, giving up and posting on SO, then finding a solution a few minutes later.
The problem was that my app was running logic tests and needed to be running application tests. The apple documentation is a little sketch on the subject, but someone else on SO wrote a pretty good solution:
how to implement application tests in xcode4?

Related

How to run UIAutomation on simulator using Xcode bots

I am using Xcode 6.3.1 and OS X server 4
i have a template for UI automation and i would like the test success failure to be logged in the bot.
is it possible?
The right answer would be that no, there is no way to get the results from Instruments after the UI Automation runs and display the results with the unit tests bot results.
But...
If you really want to hack some stuff together you really could make it work by using the info given HERE and then parsing the results and modifying the Xcode NodeJS server that displays the data to also display the UI Automation results.
OPINION:
I would say the second option is not worth the time and effort and that it would be better to use a framework like KIF which runs UI tests like unit tests so you can get the results in Xcode Bot.

Titanium NSInvalidArgumentException

I'm trying to build a crossplatform (Android-ios) mobile application, using Titanium SDK. I didn't have a chance for a long time to build it for ios, I only used my Windows-android combination, to test it, and it works great on the Android system. But when i try to build it on the mac for the ios, i get this message, and the application shuts down in a second:
The application has crashed with an uncaught exception
'NSInvalidArgumentException'.
Since i can not provide any relevant code, because the exception doesn't show what's the problem with my javascript code, and I certainly didn't write any native, ios specific code, i have no idea, what to do.
From the few posts i have found here is what i have tried:
Restart Titanium Studio
Clean the project
Made sure to close any ResultSet, and DB objects when done with
them (as suggested here: topic)
Test the code on both 3.0.0 and 2.x.x versions
I'm looking forward to any advice, on how you solved this problem, if you had it!
Thanks in advance!
Update:
The problem was the following: I called hasOwnProperty on Titanium UI elements, and on the ios version these elements don't have this function (which is weird, since every javascript objects have it, if i'm not mistaken).
If you have similar problems, i recomend reading this article, besides mr.VVoos answer, it helps a lot in avoiding the problems i had!
I'm developing with Titanim and iOS & Android for a long time. Usually there are many differences between iOS and Android parts of the code.
In most cases this exceptions means that an operation is called that is not available for the called class. (In Java this would mean: Class.method() -> Class has no method called method()).
You can try to run the app in debug mode (on iOS Simulator). There is a big advantage debuggin iOS compared to Android. Usually the iOS simulator stops if there is an exception and it shows the JavaScript code that caused the exception. Unfortunately this doesn't work all the time and it only works on simulator.
If this does not provide any further information you can do the following:
- go to your app.js and set a breakpoint in one of the first lines.
- start app in debug mode.
- move on this breakpoint each time until your app crashes - maybe then you are able to detect the error or provide further information.
One last tip: Check your code if there are any platform-specific parts. (Like Android Intents and something that is not available on iOS).
I know that this can be very ugly but we had to solve many of these nasty issues while migrating from iOS to Android.

Functional testing coverage Tool on apache and jboss

I'm looking for some tool which will provide me the code coverage of my functional tests (Not the unit testing code coverage ). To elaborate more, assume QA team executes their tests suites using selenium. At the end of the tests, I would like to know the amount of code (target code , not the test code base) got invoked / tested .
I found a similar post for .Net , but in my case the webserver is Apache and application server is jBoss
Coverage analysis for Functional Tests
Also, we have never done this type of analysis before, is this worth the effort, anyone who tried it ?
I used to do code coverage testing on assembly code and Java code. It is definitely worth it. You will find as you get the coverage close to 100% that it gets more and more difficult to construct tests for the remaining code.
You may even find code that you can prove can never be executed. You will find code on the fringes that has never been tested and you will be forced to run multi user tests to force race conditions to occur, assuming that the code had taken these into account.
On the assembly code, I had a 3000 line assembly program that took several months to test, but ran for 9 years without any bugs. Coverage testing proved its worth in that case as this code was deep inside a language interpreter.
As far as Java goes I used Clover: http://www.atlassian.com/software/clover/overview
This post: Open source code coverage libraries for JDK7? recommends Jacoco, but I've never tried it.
Thanks for the pointers #Peter Wooster. I did a lot of digging into the clover documentation but unfortunately there is not even a good indication that functional / integration is supported by clover, leave alone a good documentation.
Lucky I got to a link within the clover documentation itself which talks about this and looks promising (Thanks to Google search). I was using the ant so didn't even search in this Maven2 area. This talks about ant as well though :)
https://confluence.atlassian.com/display/CLOVER/Using+Clover+in+various+environment+configurations
I will be trying this , will update more on this soon !

Unit testing and iPhone development

I'm currently using OCUnit that ships with Xcode 3.2.4 for doing unit testing of my application. My workflow is often to set some break points in a failing unittestin order to quickly inspect the state. I'm using Apple's OCUnit setup:
http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html
but the setup from above gives me some headaches. Apple distinguish between Application tests and Logic tests. As I see it:
You cannot debug logic tests. It's as if they're invisibly run when you build your project.
You can debug application tests, but you have to run these on the device and not the simulator (what is the reason for this?)
This means that everything moves kind of slowly with my current workflow. Any hints on getting app tests to run on the simulator? Or any pin pointers to another test-framework?
Would eg. google-toolbox-for-mac work better in general or for my specific needs?
Also, general comments on using breakpoints in the unit tests are welcome! :-)
I have used the Google Toolbox testing rig in the past and it worked fine, it ran both on the Simulator and the device and I could debug my tests if I wanted to. Recently I got fed up with bundling so much code with each of my projects and tried the Apple way.
I also find the logic/app tests split weird, especially as I can’t find any way to debug the logic tests now. (And if you’re using some parts of AVFoundation that won’t build for Simulator, you are apparently out of luck with logic tests completely, which seems strange.) One of the pros is that I can run the logic tests quickly during build.
I guess this does not help you that much – the point is that you can debug the tests under GTM. And you might also want to check out this related question.
I know this isn't really a good answer, nor is it completely helpful to your cause. But I've been using NSLog to run my unit tests (if nothing outputs to the console, then success). When I comment out my tests method then the tests wouldn't run. I found this much more predictable and reliable than OCUnit. I'd much rather use a real true unit tester, but it was too frustrating to deal with the often strange errors that could occur from OCUnit and also the other shortfalls/lack of features you describe above.

iPhone Simulator is slow compared to device

I've been working on a new app, and when I run it on the simulator, it's VERY slow. There's nothing fancy in the app, just UINavigationControllers and text. The slowness only occurs if I launch the app from Xcode (with or without debugging on, doesn't matter). If I run the app on my iPhone or launch it directly from the simulator by clicking it's icon from SpringBoard, the performance problems all disappear.
For what it's worth, all my other apps perform just fine when run launched from Xcode in the simulator, so it must be something specific to this app. Has anyone experienced this before?
UPDATE: There is no performance hit when the app is run through Instruments either. I'm not using any 3rd party libraries. It's all calls to the Apple SDK.
Thanks,
Arash
Have you looked at it in Instruments to see where it's spending its time? No reason to guess when you can test.
Running an app in the simulator while in active debugging will always make the app slower. Always, and in a way that is exactly what you are describing.
Basically, "Build and Go" will be slow because its running the debugger.
This is different from "Debug" vs. "Release". The debug build will run fast if you aren't actually debugging it.
Are you using NSLog() to print a large amount of information? When you launch through Xcode, that information is piped to the debugging console and, if there's a lot, will take time to update the window. When you launch directly or on the device, the data is simply stored in a file, which generates less overhead.
I once reduced a program's run time from several minutes to a few seconds simply by removing logging statements. Unfortunately, it was for a timed programming contest.
I had the exact same problem and spent about 2hrs now to solve it. In my case I think it was because I had "Enable Guard Malloc" set. If it wasn't that, my other guess is bad karma.
Simulator Debug, You should need to be ensure when your app running on simulator debug->slow animations isn't check marked