Touch.Unit Automation Revisited

The basics for test automation have been in place for a while. However that was more potential for automation that real automation. Too many things, outside the Touch.Unit application, were still missing.

Since that time Rolf has filled those missing pieces, mainly in the Touch.Server tool, to allow Touch.Unit projects to be build, executed on the simulator and/or on devices, and to receive all the test results on a local file for further processing and reporting.

So how do I do that ? All the tools are already available, i.e. it’s all in the stable MonoTouch 5.2.x releases. All it takes is some minimal scripting to adapt it to your application.

Here’s an example (Makefile) of how this can be done for Touch.Unit itself (i.e. the sample tests it includes).

MDTOOL=/Applications/MonoDevelop.app/Contents/MacOS/mdtool
MTOUCH=/Developer/MonoTouch/usr/bin/mtouch
TOUCH_SERVER=./Touch.Server/bin/Debug/Touch.Server.exe

all: build-simulator build-device

run run-test: run-simulator run-device

$(TOUCH_SERVER):
	cd Touch.Server && xbuild

build-simulator:
	$(MDTOOL) -v build -t:Build "-c:Debug|iPhoneSimulator" Touch.Unit.sln

run-simulator: build-simulator Touch.Server
	rm -f sim-results.log
	mono --debug $(TOUCH_SERVER) --launchsim bin/iPhoneSimulator/Debug/TouchUnit.app -autoexit -logfile=sim-results.log
	cat sim-results.log

build-device:
	$(MDTOOL) -v build -t:Build "-c:Release|iPhone" Touch.Unit.sln

run-device: build-device
	$(MTOUCH) --installdev bin/iPhone/Release/TouchUnit.app
	# kill an existing instance (based on the bundle id)
	$(MTOUCH) --killdev com.xamarin.touch-unit
	rm -f dev-results.log
	mono --debug $(TOUCH_SERVER) --launchdev com.xamarin.touch-unit -autoexit -logfile=dev-results.log
	cat dev-results.log

This small Makefile shows you how to use:

  • mdtool to build an existing MonoDevelop solution, Debug or Release;
  • mtouch to install and kill (running) applications on devices; and
  • Touch.Server to start application, including specifying arguments.

All of them can be useful in other circumstances but for our purpose you can simply issue a make run-test from a terminal window to execute the test cases on both the simulator and a connected device.

p.s. you should all encourage Rolf to blog more often has he’s doing incredible stuff all around MonoTouch.

Advertisements

About spouliot

Xamarin Hacker, Mono Contributor, Open Source Enthusiast with strong interests in Code Analysis, Cryptography and Security. Presently working on MonoTouch, previous projects were Moonlight and libgdiplus and a lot of the cryptographic work done on Mono.
This entry was posted in mono, monotouch, touch.unit, xamarin. Bookmark the permalink.

2 Responses to Touch.Unit Automation Revisited

  1. Michael Probst says:

    Hi.. I’am currently want my jenkins to run automatic Nunit tests with Touch.Unit. I already set up the project and it run like a charme over the terminal (“make run-simulator”). It opens the simulator, run the included tests in project and write down the results in console.
    But – this exact ‘make run-simulator’ doesn’t work over jenkins. He execute the make file and stops at “Touch.Unit Simple Server listening on: 0.0.0.0:16384” – nothing else happens after this output. Any ideas? 🙂 Would be great..

  2. spouliot says:

    When executed under jenkins you’re likely running on a different user account, using different environment variables… You should try to run “make run-simulator” under the same “jenkins” identify and see if it runs. You can also dump your environment variables to a log file and compare them to yours.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s