Is it possible to start an application test that runs in the simulator with a terminal command(s)?
Thanks
Yes, I got it to work. My solution is somehow rough and might not be suitable in every case.
Disclaimer: This solution requires to edit system files. It works for me, but may mess up XCode's unit testing stack, especially if you do not understand what you are doing.
In /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests
replace
if [ "${TEST_HOST}" != "" ]; then
Warning ${LINENO} "Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set)."
else
with
if [ "${TEST_HOST}" != "" ]; then
mkdir -p "${BUILT_PRODUCTS_DIR}/Documents"
mkdir -p "${BUILT_PRODUCTS_DIR}/Library/Caches"
mkdir -p "${BUILT_PRODUCTS_DIR}/Library/Preferences"
mkdir -p "${BUILT_PRODUCTS_DIR}/tmp"
export CFFIXED_USER_HOME="${BUILT_PRODUCTS_DIR}/"
RunTestsForApplication "${TEST_HOST}" "${TEST_BUNDLE_PATH}"
else
You may move the fixed user home to a different location, but I think you would need to move the .app and .octest bundles along.
Add -RegisterForSystemEvents
to the OTHER_TEST_FLAGS
build setting of your test bundle.
Make sure your test bundle contains a run script build phase with the contents
# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
Create a new scheme for your tests.
You should be able to run the tests from the command line using the standard xcodebuild:
xcodebuild -workspace $(WORKSPACE_NAME).xcworkspace -scheme $(TEST_SCHEME) -configuration debug -sdk iphonesimulator
The simulator must not be running, at the time you what to run the tests.
I hope this information is complete, if something doesn't work as expected please ask.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With