How do I catch OCUnit's test fail/success in command line? - iphone

My Expect: # Build Successed # and # Test Failed #
Actual Result: only # Build Succeeded #
How do I get fail/success in command line? [iphone, objective-c, xcode4, OCUnit]
I'm newbe of OCUnit and Xcode4. I create project:
https://github.com/sanemat/HogeHoge
This is scafold code by xcode4. I run test in xcode gui, #Test Failed# appear in successfully. In commandline (I want to use jenkins),I use following command.
xcodebuild -target HogeHogeTests -configuration Debug -sdk iphonesimulator4.3 clean build
I see # Build Succeeded # and then completed. I want run test and get it's result. How?
Edited:
I found BPOCUnitXMLReporter. This is for MacOS. I forked and adjusted iOS.

I found BPOCUnitXMLReporter. This is for MacOS. I forked and adjusted iOS.

Try the Text Finder Plugin It allows you to search a log for a string, and set pass or fail based on that.

You can integrate a custom test logger with OCUnit. See my answer here:
How do I trap OCUnit test pass/failure messages/events

what you're looking for is this undocumented argument (you do need sdk and target too) to run your OCUnit Tests from the terminal
xcodebuild -target MyTarget -sdk iphonesimulator TEST_AFTER_BUILD=YES

Related

How can I build a Swift Package for iOS over command line?

In Xcode, I can select my destination as a "generic iOS device" or any iOS simulator, and my package will build platform-specific code for ios.
Via command line "swift build" only builds my target for macOS.
I want to build the target for iOS for CI purposes. The problem with building for macOS is that UIKit-specific code won't be built.
For example:
#if canImport(UIKit)
// some invalid code
#endif
The invalid code will not be noticed and will pass the build phase.
Ideally, I could say something like swift build -platform iOS. Is there a way to do something like this?
At time of writing (Feb 16, 2019), a working solution is:
swift build -v \
-Xswiftc "-sdk" \
-Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" \
-Xswiftc "-target" \
-Xswiftc "x86_64-apple-ios13.0-simulator"
This command uses -Xswiftc to workaround the issue by overriding the sdk from macOS to iphonesimulator.
Strictly we add these flags so developers can work around issues, but they also should report a bug so that we can provide a proper solution for their needs.
Source
So I'm guessing there will be a more elegant solution in the future.
Starting with Xcode 11, xcodebuild supports SwiftPM packages out of the box.
An example invocation would look like this:
xcodebuild -scheme Foo \
-destination 'platform=iOS Simulator,OS=13.5,name=iPhone 11 Pro'
where Foo would be the name of the library product you're trying to build. You can
get the full list of available schemes for you SwiftPM package with xcodebuild -list.
You can get the list of available destinations for a given scheme with this invocation:
xcodebuild -showdestinations -scheme Foo

Xcode execute “Test” from command line?

I would like to build my iOS project (cocoapods) from command line, so I will be able to build it on jenkins. First trigger all unit tests after every commit. On Xcode it is easy, Product -> Test. Can I somehow check what command is executed when I click on it?
I found this: developer.apple
Maybe someone in the future will look for this, so this is how I solved it:
xcodebuild test -workspace 'MyWorkspace.xcworkspace' -scheme 'SchemaTests' -destination 'platform=iOS Simulator,name=iPhone 8,OS=12.1'

Cannot build XCode project from command line but can from XCode

I've created in XCode a simple navigation-based iPhone app. The app builds and runs properly from under XCode but I cannot get it to build from command line.
From terminal I execute:
xcodebuild -project George.xcodeproj -alltargets -parallelizeTargets -configuration Debug build
but I get that error:
=== BUILD NATIVE TARGET George OF PROJECT George WITH CONFIGURATION Debug ===
Check dependencies
[BEROR]Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
Is there something wrong with the way I try to handle it?
In addition to unlocking the keychain, you might also specify the codesign identity (or set it in your target). Development certs take the form 'iPhone Developer: Company Inc', distribution certs like this 'iPhone Distribution: Company Inc'.
xcodebuild -project George.xcodeproj -alltargets -parallelizeTargets -configuration Debug build CODE_SIGN_IDENTITY='iPhone Developer: Company Inc'
You can build from the command-line a build targeted at the simulator without signing issues.
This solved the signing issue for me:
xcodebuild -sdk iphonesimulator
Source:
xcodebuild Code Sign error: No matching codesigning identity found:
That's particularly useful if the command line build is there only to sanity check the source code in a continuous integration setup.
Most probably your keychain is locked. Try unlocking it before executing the script, you can do it from command line (right before building):
security unlock -p YourPasswordToKeychain ~/Library/Keychains/login.keychain
Note, I'm using "login" keychain which could be different in your case
Also, if that doesn't help, try removing all other parameters and just leave smth like this:
xcodebuild -configuration Debug and clean beforehand xcodebuild -configuration Debug clean
I'm using shenzhen, it shows this error too.
Turns out, it happens when I plug in my iPad but it is not in the provision profile. By passing --verbose to shenzhen. it shows:
Check dependencies
Code Sign error: No matching provisioning profiles found: None of the valid provisioning profiles include the devices:
XXXX’s iPad
CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 8.3'
unplug the device, everything works just fine...
Depending on the purpose of your script, it may also be sufficient to just turn off code signing in the script, which you can do by setting CODE_SIGN_IDENTITY=''
xcodebuild -project George.xcodeproj -alltargets -parallelizeTargets -configuration Debug build CODE_SIGN_IDENTITY=''
Obviously that's no good if you are trying to do a final build from a script, but it may be fine if you're just trying to do a test build for continuous integration (eg from Jenkins, to make sure that nobody has broken anything).
I had an archiving error similar but not quite the same as the original post:
** ARCHIVE FAILED **
The following build commands failed:
Check dependencies
(1 failure)
This turned out to be a missing Application Service (in my case, the HealthKit service/entitlement), which I had enabled in my development App ID but not my production App ID.
You enable services in the Apple Member Center: https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action
This can be fixed in XCode 8.0 by changing from "iOS Distribution" to "iOS Development" in XCode. It doesn't seem like it should work, but it does for some reason.

(iphone) build xcode4 project from command line

I've used to build my project with
xcodebuild -proj MyProject.xcodeproj -target MyTarget - configuration Debug -sdk iphonesimulator4.3
this works(it builds fine) but when I hit run in xcode, it recompiles.
(with xcode3, there was no need to rebuild once I build using command line)
I suspect xcode build use workspace/scheme rather than project/target.
How do I find out the workspace name that my current xcode project is using?
Thank you
edit
Chetan's links gave me directions what to look for.
xcode4 stores build output in ~/Library/...
whereas xcodebuild -project .. saves build output in project's build directory.
(if you want the workspace capability, you can't use the build directory for build output)
I created a workspace containing my project and ran
xcodebuild -workspace myWorkSpace -scheme myScheme
this saves build output in ~/Library/...../Debug-iphoneos
whereas xcode4 run button from the same workspace and same scheme saves output in
~/Library/..../Debug-iphonesimulator
any guess on why xcodebuild command uses Debug-iphoneos? :(
edit2
xcodebuild -workspace myWorkSpace -scheme myScheme -sdk iphonesimulator4.3
specifying sdk solved it
I know it isn't strictly the answer to your question, but you can configure the output directory of your build using the CONFIGURATION_BUILD_DIR environment variable.
Source: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/0-Introduction/introduction.html#//apple_ref/doc/uid/TP40003931-CH1-SW1

iphone sdk 4.3 running unit test from command line

i like to run test cases from the command line but there is a little problem… maybe someone can help me…
i' ve created a simple HelloWorld Project with XCode4! The build works fine.
xcodebuild -project HelloWorld.xcodeproj -target HelloWorld -sdk iphonesimulator4.3 -configuration "Debug"
But the test doesn't work (i use the default unit test which xcode4 creates)
xcodebuild -project HelloWorld.xcodeproj -target HelloWorldTests -sdk iphonesimulator4.3 -configuration "Debug"
Here are some interesting outputs:
=== BUILD NATIVE TARGET HelloWorld OF PROJECT HelloWorld WITH THE
DEFAULT CONFIGURATION (Release) ===
Check dependencies
And
/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/Tools/RunPlatformUnitTests:95:
warning: Skipping tests; the
iPhoneSimulator platform does not
currently support application-hosted
tests (TEST_HOST set).
I guess the last output is the problem but i haven't any idea to fix it :-(
It sounds as though you may have unit tests and application tests mixed up. Referring to the two following sources (especially the non-apple one) will help you out a lot:
Apple's Documentation
CocoaWithLove Article