Permalink
Browse files

added feature to support tests for universal apps or iPhone/iPad-only

  • Loading branch information...
1 parent 30b2620 commit f128f64e212a6e31270a3fabc39eb9783088a8a5 Sven Jansen committed Nov 26, 2012
Showing with 58 additions and 16 deletions.
  1. +7 −3 build.sh
  2. +51 −13 integration_testing.sh
View
@@ -22,8 +22,12 @@ UNITTESTNAME="${APPNAME}Tests"
## integration test specifics
# subfolder within project that contains the integration tests
UIAUTOMATIONPREFIX="${WORKSPACE}/${PROJECT_PREFIX}IntegrationTests"
-# path to UIAutomation root test script (JavaScript-File)
-UIAUTOMATIONTESTPATH="${UIAUTOMATIONPREFIX}/integration_tests.js"
+# path to UIAutomation root test script (JavaScript-File) -> name without *.js suffix!!!
+# if you like to test universal apps you have to provide two integration test files.
+# one with "_iphone.js" suffix and another one with "_ipad.js"
+UIAUTOMATIONTESTPATH="${UIAUTOMATIONPREFIX}/integration_tests"
+# flag to switch between universal or iPhone/iPad-only app (1 or 0)
+IS_UNIVERSAL=0
## simulator test specifics
# simulator sdk version for integration tests
@@ -58,7 +62,7 @@ fi
##
# if the user enabled UIAutomation testing (checkbox in Jenkins), run the tests before building the App
if [ $UIAutomation_Test == true ]; then
- RESULT=$(/bin/sh ~/UnitTestScripts/integration_testing.sh $SIMULATORSDK $APPNAME $UIAUTOMATIONPREFIX $UIAUTOMATIONTESTPATH)
+ RESULT=$(/bin/sh ~/UnitTestScripts/integration_testing.sh $SIMULATORSDK $APPNAME $UIAUTOMATIONPREFIX $UIAUTOMATIONTESTPATH $IS_UNIVERSAL)
if [ $RESULT -ne 0 ]; then
echo "**** integration testing FAILED ****"
exit 1
View
@@ -3,29 +3,67 @@ SIMULATORSDK=$1
APPNAME=$2
UIAUTOMATIONPREFIX=$3
UIAUTOMATIONTESTPATH=$4
+IS_UNIVERSAL=$5
TESTRESULTSPATH=$UIAUTOMATIONPREFIX/TestResults
# boolean value for testResults
TESTSUCCESSFUL=false
-# build the project especially with Debug-scheme on iOS Simulator to make this build runnable with instruments (make sure architecture i386 is enabled in debug scheme)
-xcodebuild -arch i386 -configuration Debug -sdk $SIMULATORSDK clean build
-
-# run Instruments from command line combined with the *.app file and the JavaScript test script. Results for every run in Instruments are stored in $WORKSPACE/TestResults.
-# stdout is passed to an log-File just for this command
-xcrun instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate $WORKSPACE/build/Debug-iphonesimulator/$APPNAME.app -e UIASCRIPT $UIAUTOMATIONTESTPATH -e UIARESULTSPATH $WORKSPACE/TestResults 1>IntegrationTest.log
-
-# remove all *.trace files because in most cases they are broken and we don't need them (-> garbage), because we have all necessary information in the log-file
-rm -r $WORKSPACE/*.trace
-
# save the date/time at first to be able to compare with the build-time later
NOW=$(date +%d.%m.%y/%T)
# create a nice title including the BuildNumber and the Date (stored in first line of this script)
SUBJECT="Build: "$BUILD_NUMBER
SUBJECT=$SUBJECT" - Date:"
SUBJECT=$SUBJECT$NOW
+echo "IS_UNIVERSAL:"
+echo $IS_UNIVERSAL
+
+# run Instruments from command line combined with the *.app file and the JavaScript test script. Results for every run in Instruments are stored in $WORKSPACE/TestResults.
+# stdout is passed to an log-File just for this command
+if [ ${IS_UNIVERSAL} -ne 1 ] ; then
+echo "run iPhone/iPad-only UITest"
+ # build the project especially with Debug-scheme on iOS Simulator to make this build runnable with instruments (make sure architecture i386 is enabled in debug scheme)
+ xcodebuild -arch i386 -configuration Debug -sdk $SIMULATORSDK clean build
+
+xcrun instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate $WORKSPACE/build/Debug-iphonesimulator/$APPNAME.app -e UIASCRIPT $UIAUTOMATIONTESTPATH.js -e UIARESULTSPATH $WORKSPACE/TestResults 1>IntegrationTest.log
+else
+echo "run iPhone UI Test"
+ # build the iPhone app
+ xcodebuild -arch i386 -configuration Debug -sdk $SIMULATORSDK TARGETED_DEVICE_FAMILY=1 clean build
+
+ # run iPhone UI Test
+ xcrun instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate $WORKSPACE/build/Debug-iphonesimulator/$APPNAME.app -e UIASCRIPT ${UIAUTOMATIONTESTPATH}_iphone.js -e UIARESULTSPATH $WORKSPACE/TestResults 1>IntegrationTest_iPhone.log
+
+
+ # if some tests of UIAutomation fail a Message containing the word "Fail" will be presented in the log-file
+ # search for "Fail:" and count the number of occurrences
+ result=$(grep "Fail:" -F IntegrationTest.log | wc -l)
+
+ # locating the active run (latest run)
+ ACTIVE_RUN=$(ls -1t ${WORKSPACE}/TestResults|grep "Run" -m1)
+
+ # transform the resulting PLIST into some nice HTML
+ xsltproc --stringparam Title "${SUBJECT}" --stringparam ScreenshotPathPrefix "${ACTIVE_RUN}/" --stringparam SmileyPathPrefix "/userContent/TestResults/images/" --output "${WORKSPACE}/TestResults/IntegrationTesting_iPhone.html" ~/UnitTestScripts/integration_test_result_transform.xsl "${WORKSPACE}/TestResults/${ACTIVE_RUN}/Automation Results.plist"
+
+ if [ $result -ne 0 ] ; then
+ # exit this script with 1 to tell Jenkins that this build didn't complete successfully
+ exit 1
+ fi
+
+ echo "run iPad UI Test"
+ # build the iPad app
+ xcodebuild -arch i386 -configuration Debug -sdk $SIMULATORSDK TARGETED_DEVICE_FAMILY=2 clean build
+
+ # run iPad UI Test
+ xcrun instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate $WORKSPACE/build/Debug-iphonesimulator/$APPNAME.app -e UIASCRIPT ${UIAUTOMATIONTESTPATH}_ipad.js -e UIARESULTSPATH $WORKSPACE/TestResults 1>IntegrationTest_iPad.log
+
+fi
+
+# remove all *.trace files because in most cases they are broken and we don't need them (-> garbage), because we have all necessary information in the log-file
+rm -r $WORKSPACE/*.trace
+
# if some tests of UIAutomation fail a Message containing the word "Fail" will be presented in the log-file
# search for "Fail:" and count the number of occurrences
result=$(grep "Fail:" -F IntegrationTest.log | wc -l)
@@ -37,8 +75,8 @@ ACTIVE_RUN=$(ls -1t ${WORKSPACE}/TestResults|grep "Run" -m1)
xsltproc --stringparam Title "${SUBJECT}" --stringparam ScreenshotPathPrefix "${ACTIVE_RUN}/" --stringparam SmileyPathPrefix "/userContent/TestResults/images/" --output "${WORKSPACE}/TestResults/IntegrationTesting.html" ~/UnitTestScripts/integration_test_result_transform.xsl "${WORKSPACE}/TestResults/${ACTIVE_RUN}/Automation Results.plist"
if [ $result -ne 0 ] ; then
- # exit this script with 1 to tell Jenkins that this build didn't complete successfully
- exit 1
+# exit this script with 1 to tell Jenkins that this build didn't complete successfully
+exit 1
fi
-#
+
exit 0

0 comments on commit f128f64

Please sign in to comment.