I have executed a suite of tests on Unit Test bundle from Xcode with a code coverage option enabled.
Question: Where are located a coverage result files on my computer?
You can find xcresult containing Xcode Test coverage of your project DerivedData
For Example
/Users/*****/Library/Developer/Xcode/DerivedData/********/Logs/Test/Test-YOUR-PROJECT-NAME-2020.06.08_16-41-38-+0900.xcresult
Related
I create an application with multiple build config, bundle id, and product name. I can run the unit test but in the unit test code, there is an error shows No such module 'ProjectName' like in the picture below. Still, it can run the unit test and the test is passed as well. It can't use the auto complete, though.
I have cleaned the build folder and restart the Xcode but it's not work.
I don't know what's going on. Could someone give me some workaround?
Update
I found the solution. Just change the build scheme in Use [build scheme] for command-line builds to your unit test build scheme test target at the project level on info tab. Then everything works fine.
just try to clean and restart Xcode it will work properly
Delete derived data https://programmingwithswift.com/delete-derived-data-xcode/
Clean the project with cmd + k
Build and re-run the unit tests with cmd + u
I found the solution. Just change the build scheme in Use [build scheme] for command-line builds to your unit test build scheme test target at the project level on info tab. Then everything works fine.
After running unit tests, I used to find two files in the Tests folder for the Derived Data of Xcode - StandardOutputAndStandardError.txt and TestSummaries.plist files. However, in Xcode 10 I'm unable to find these files. How can I get the test logs in Xcode 10.
StandardOutputAndStandardError.txt file, you are looking for, is now located in:
Derived data
\your project folder
\Logs\Test
\.xcresult file
\Diagnostics
\<YourAppNameUITests folder>
\<YourAppNameUITests folder>
again and there it is.
For <YourAppNameUITests folder> there is also a folder with log from simulator.
I am getting this warning in Objective-C:
RunUnitTests is obsolete. To run unit tests for your target, use the Test scheme action in the Xcode IDE and the test action in xcodebuild.
I did some googling around and found a solution to add TEST_AFTER_BUILD and set it to YES in User-Defined settings. After doing this the warning is still there. What am I doing wrong?
You need to delete the Run Script build phase that invokes RunUnitTests from your unit test bundle target, as suggested by the Xcode info message when it tries to build your unit test bundle.
This is the offending Run Script build phase, likely stuck there by a previous version of Xcode:
I want to view the code coverage by running gcovr on generated gcda files. Jenkins seems to put the generated gcda files in Users/../Library/developer/Xcode/DerivedData/../../../i386. I expect them to be in Users/Shared/Jenkins/workspace/../build/example.build/Debug-iphonesimulator/example.build/Objects-normal/i386
When i run my IOS project with XCode locally it does generate gcda files and i can view my coverage.
Im running xcode 5 and all tests are created with XCTest.
I've set 'Generate Test Coverage Files=YES' and 'Instrument Program Flow=YES' for debug and release, basicly i have done everything according to this post
In Jenkins i use the xcode plugin to build. It has two build commands. The first one builds with the target "example" and configuration debug.
The second Xcode build command builds with the target "ExampleTests", configuration debug, arguments" test -destination OS=7.0,name=”iPhone Retina (4-inch)” and a scheme . In the output i can see the test being run and the simulator starts on the building machnine.
It seems i have missed something maybe in the project setting or havent set something right in the jenkins job. Maybe something like TEST_AFTER_BUILD=YES only then for XCode5.
As you recognised the .gcda files are put in the "wrong" directory.
Do the following:
Select your application target in your Xcode-Project and go to "Editor -> Add Build Phase -> Add Run Script Build Phase"
Paste this script into the script field:
echo "Creating derivedDataDirectory file"
echo "${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}" > ${PROJECT_DIR}/derivedDataDirectory
XCode setup
(This creates a file with the path to the derivedDataDirectory)
Go to your jenkins project, click on "Add build step" and select "Execute shell".
Paste this script into the "Command" field:
#CopyCodeCoverageFile
echo "Start copying code coverage Files"
projectname="[YOUR PROJECTNAME]"
source=$(cat ${WORKSPACE}/$projectname/derivedDataDirectory)
cp -a $source/. ${WORKSPACE}/$projectname/
#CodeCoverage
echo "Start CodeCoverage"
cd ${WORKSPACE}/$projectname
[YOUR PATH TO GCOVR]/gcovr -r /private/tmp/workspace/${JOB_NAME}/$projectname --xml > ${WORKSPACE}/$projectname/test-reports/coverage.xml
Insert [YOUR PROJECTNAME] and [YOUR PATH TO GCOVR]. If your PROJECTNAME or target has
spaces in it, this will cause trouble! Make sure all the paths are correct!
This works for me and if all your paths are correct it should work for you to.
Im running XCTests on Jenkins using XCode 5. This should be the same as your setup.
If you dont use gcovr to generate code coverage for cobertura you can delete the last step
in the script. If you are experiencing problems with gvovr try using gcovr 3.0 instead of
3.1!
Tell me if something is not working for you or you found a better solution!
I created a few test cases and they all passed... That's because they are not being run.
From Xcode, I get:
Test Suite 'All tests' started at...
Test Suite 'All tests' finished at...
Executed 0 tests, with 0 failures (0 unexpected) in 0.00 seconds
The project (and unit test classes) build successfully.
All my test classes have MyApp_appTests as Target Membership selected. Production classes have MyApp_app & MyApp_appTests targets selected.
I verified the MyApp_appTests Target Build Settings (Bundle Loader & Test Host).
Bundle Loader (Debug): $(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp
Test Host (Debug): $(BUNDLE_LOADER)
I have imported SenTestingKit.framework (through Targets Build Phases "Link Binary With Libraries").
All my tests start with -(void)testThat...
I have also checked a few stackoverflow.com questions:
stackoverflow.com/questions/8632254/xcode-4-2-cant-run-unit-test
stackoverflow.com/questions/3608484/ocunit-tests-not-running-not-being-found
stackoverflow.com/questions/16672616/ocunit-test-cases-not-running
and this post:
twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/
I don't know where to look for... Any help is greatly appreciated!
For me worked changing "Wrapper extension" from "octest" to "xctest" in Build Settings for tests target
Xcode 5 now used XCTestCase, not SenTest. Apple is now supporting Unit Testing more directly including their own version of SenTest named XCTestCase. Additionally the UI is much improved, allowing individual tests to be run, a Test Navigator and no longer creating .h test files. Note that the test macros are not renames with an XC prefix.
See the WWDC-13 video 409: "Testing in Xcode 5".
If you use the Xcode 5 template to create the testing environment the project will include a test target and a working (and failing) test.
If you are creating a new test target in Xcode 5+ and planning to use SenTestKit for unit tests, changing the 'Wrapper Extension' build setting of your test target to 'octest' from the default 'xctest' will help execute the test cases.
I had this problem with Xcode 7.3, what worked for me was running the application on the device once and then running the tests.