execute xcodebuild test with '-enableCodeCoverage=YES' option but the result Coverage.profdata looks invalid - xcodebuild

Recently I'm preparing UITesting for our app.
My XCode version is 7.3.1(7D1014).
When I had executed 'UITesting' in XCode as manual, I got the coverage report successfully as below.
UITesting executed by xcode
But I execute test that project with command line, created "Coverage.profdata" file size is different with xcode. And change that coverage data to 'cobertura' using 'slather', the result is zero.
Here is my xcodebuild statement.
xcodebuild test -project SampleTestApp.xcodeproj -scheme SampleTestApp -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 5s,OS=9.3' -enableCodeCoverage YES
I think, I missed something. Is there anyone who experienced like me?
I need your help.
I looked log file furthermore. And I found something different between XCode testing and xcodebuild testing.
A. XCode Testing Log(~/Library/Developer/Xcode/DerivedData/MyProjectXXX/Logs/Test/XXXXX/Session-XXXXXX.log)
"wait_for_debugger" set 1 in Tests-Runner options
B. xcodebuild Testing Log(~/Library/Developer/Xcode/DerivedData/MyProjectXXX/Logs/Test/YYYYY/Session-YYYYY.log)
"wait_for_debugger" set 0 in Tests-Runner options
I wonder i can change this option value when executes test-runner.

Related

XCUITEST is not running while running from from terminal using xcodebuildcommand

I have more than 50 test cases in my UI-TEST scheme and I am running it via the below command
xcodebuild test -workspace tribo.xcworkspace -scheme triboUITests -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone X,OS=12.4'
what happens is the RAM of my Mac machine shoots up and the system hangs up , I have attached the activity monitor report tooenter image description here
can anyone help me in running all XCUITEST cases present in scheme from terminal
The console command itself seems legit.
The RAM problem also could be caused by inaccurate resource management in test code.
Consider inspecting your code for possible memory leakings and other bugs.
You can run a specific test or tests as part of the xcodebuild invocation.
From the xcodebuild help command line:
-only-testing:TEST-IDENTIFIER constrains testing by specifying tests to include, and excluding other tests
-skip-testing constrains testing by specifying tests to exclude, but including other tests
-skip-testing:TEST-IDENTIFIER constrains testing by specifying tests to exclude, but including other tests
Using these commands may help you understand which tests are causing the issue.
You could also use the Xcode Memory Graph Debugger (see this link:
https://medium.com/zendesk-engineering/ios-identifying-memory-leaks-using-the-xcode-memory-graph-debugger-e84f097b9d15
Finally, you if you are trying to run all your tests in parallel, you may have too many simulators running on the machine.

iOS - How to pass build params in fastlane snapshot

I am using fastlane snapshot tool for taking snapshot for app screens.
According to fastlane community, i need to run,
fastlane snapshot init
Then after configuring project ui test target, i need to run
fastlane snapshot
But if I want to provide some build parameters like, xcodebuild test test-only params, how can I do that. For example i want to build like,
xcodebuild test -workspace <path>
-scheme <name>
-destination <specifier>
-only-testing:TestBundleA/TestSuiteA/TestCaseA
-only-testing:TestBundleB/TestSuiteB
-only-testing:TestBundleC
I see,
fastlane snapshot --help
Then I added in Snapfile,
xcargs -only-testing:TestBundleB/TestSuiteB
But this gives error
(eval):36: syntax error, unexpected tSYMBEG, expecting keyword_do or
'{' or '(' only-testing:TestBundleB/TestSuiteB
How can i solve this error?
I am not familiar with running snapshot from the command line, so if you can, I would recommend creating a fastlane/Fastfile (or editing it if it already exists) to have a lane that calls snapshot with the options that you are looking for. You can call it with its various parameters as explained in the docs
The example shows you how snapshot could be called, and the Parameters table describes the other parameters you can pass to the fastlane Action.
To pass xcargs via the Snapfile, try xcargs "-only-testing:TestBundleB/TestSuiteB" in your Snapfile. See this Issue.

Is it possible to run individual test cases/test classes on the command line with xcode 5?

I can run all unit tests using the following command:
xcodebuild test -workspace Project.xcworkspace -scheme Scheme -sdk iphonesimulator7.0 -destination platform='iOS Simulator',OS=7.0,name='iPhone Retina (4-inch)'
Is there anything I can pass to this to run individual unit tests/classes in the same way that you can using the Xcode UI?
Cheers.
Not that I know of, and it's not on the man page either. But you have such option in the excellent xctool (-only SomeTestTarget:SomeTestClass/testSomeMethod).
For those who are using later versions of Xcode (8.0+) and may run across this post in the future (like myself), this is now possible using the -only-testing flag, which is documented in the man page for xcodebuild. The format for using the flag is as follows:
xcodebuild \
-destination "$DEST" \
-workspace "$WRKSP" \
-scheme "$SCHEME" \
-only-testing:Target/Class/Method test
You can also omit elements from the path after the -only-testing flag, e.g. -only-testing:Scheme/Class will run all these tests within that class.
Here is a related Stackoverflow question, touching on the new functionality:
How to use xcodebuild with -only-testing and -skip-testing flag?
Another way is to edit the schemer of your test file and disable/enable the tests as you please. Then you can rerun the same command through the CLI and it will only run the tests you specified above.
If you're using Kiwi, you should supposedly be able to do it using the KW_SPEC environment variable. I haven't been able to, though: Running a single KIWI spec with xctool.

All tests did not finish - xcode 4.5

When i try to run the unit test for my projects, i get test succeeded. But in the log navigator i get warning saying 'All tests did not finish'. But the same code works fine in another machine and all tests succeeds without any warning. I searched for other posts related this and tried everything, but nothing works for me. And also all of a sudden some unit-tests fail without any reason, but succeeds when i run it again. I even tried resetting the simulator, nothing works.
Any suggestions?
Try this... open a Terminal in your project's folder and type the following:
xcodebuild -list
If you have Unit Tests in your project you should see at least two targets: ProjectName and ProjectNameTests.
Now type the following command (note: you will need quotes around the ProjectNameTests if it has spaces):
xcodebuild -target ProjectNameTests build
You will almost certainly see something like the following towards the end of the output:
/Applications/Xcode.app/Contents/Developer/Tools/RunUnitTests:68: note: RunUnitTests exited without running tests because TEST_AFTER_BUILD was set to NO.
You can fix this in Xcode by selecting your project in the Project Navigator (Cmd-1), selecting your ProjectNameTests target, selecting Build Settings and scrolling down to the Unit Testing section. Change the Test After Build setting from No to Yes and type Cmd-U to run your Unit Tests again. This time it should work.
Hope this helps!
Looks like you get this warning if you are using OCMOCK and you try to mock 'self'. Once i changed this, it fixed my problem.

iOS: XCode 4.4.1: xcodebuild error - Unable to read diagnostics from file

So I would like to use xcodebuild in Terminal to create a build from a test application (called RunTeszt1). The app is an iOS single view application with nothing in it, just created and closed.
When I this from the Terminal, the build fails.
xcodebuild -target "RunTeszt1" -sdk "$iphoneos5" -configuration Debug
The error is:
Unable to read diagnostics from file "/var/folders/6s/cjw35hhs5lb6wpnx9m8lr2km0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/RunTeszt1-Prefix-eqntxoxxhhlzvieuipqbxfumbpxb/RunTeszt1-Prefix.pch.dia" (Invalid File): Bad header in diagnostics file
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1
When I run the app from XCode (4.4.1), the build completes and everything is ok. However, If I run the Console app and inspect the results after hitting build button in XCode, I see the same error message in the console. Nevertheless the build succeeds and opens the simulator.
Is this really a bug in xcodebuild which should be sent to apple? If it is I imagine a bunch of people already sent it.
How can I either make the error go away, or stop it from cancelling the building process, so circumvent it like XCode does?
Turns out the problem was code signing. Even though I put Don't code sign in the build settings, it still hanged up on it. Also it seems "-sdk xxx" was also at fault (no matter what sdk I specified).
Running this command resulted in a successful build:
xcodebuild clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -target RunTeszt2