titanium-jasmine provides testing for Appcelerator’s Titanium Mobile applications using Pivotal’s Jasmine as the core testing framework.
Titanium Mobile translates your hard won JavaScript skills into native applications that perform and look just like they were written in Objective-C (iPhone and iPad) or Java (Android).
Jasmine is a BDD-style framework for JavaScript that makes your tests look awesome:
describe("titanium-jasmine", function() { it("should help you develop titanium applications", function() { expect(yourTests).toBe('awesome'); }); });
titanium-jasmine puts together Jasmine and Titanium Mobile, so you can write Jasmine tests that will run inside your iPhone, iPad and Android applications. titanium-jasmine is a really simple testing framework that will help you test your Titanium Mobile applications properly.
Instead of trying to mock all Titanium.* objects and functions, titanium-jasmine will run the tests on your simulator so you can keep using Titanium includes and helper functions on your code, thus making testing much easier.
* Screenshot: titanium-jasmine test results on the iPhone.
* Screenshot: titanium-jasmine test results on Android.
titanium-jasmine supports all Jasmine features from suites, specs and matchers to asynchronous testing, spying/mocking/faking and before/after functions.
Download the source code, go to the project root and type:
$ make run-iphone
* Tested with all Titanium Mobile SDK versions from 1.5.0 to 1.6.1. To change the SDK version, change the TI_SDK_VERSION configuration in the bin/titanium.sh script.
To run the application on the iPad, type:
$ make clean && make run-ipad
To run the application on Android, type:
* You must have android, applicable sdk versions, and at least one emulator device created and running.
$ make clean && make run-android
* You just have to use “make clean” before the run command if you change the device type. If you’re using the same device between executions, it’s not necessary to execute “make clean” because it will force Titanium to re-compile the entire project again, which is considerably slow.
To run the application executing the tests, go to project root and type:
$ make test-iphone
Or:
$ make test-ipad
Or:
$ make test-android
* Remember to execute “make clean” whenever you change the device type.
You don’t have to import the project on Titanium Developer. You can do that if you want, but I prefer to start from the command line. If you want to do this in your project too, just copy Makefile and the bin directory to your project.
This project comes with a sample application located in the SampleApp directory. You can inspect this sample app to understand how the testing structure works.
To use titanium-jasmine in your projects, just copy the SampleApp/Resources/test folder and modify the files accordingly.
Here are some details about some key files and directories:
- SampleApp/Resources/test/lib contains Jasmine library and the reporter that displays tests output on the application.
- SampleApp/Resources/test/enabled.js is the file that controls if the application is in “test mode” or not. This file does not exist in the repository because it is created by the “make” script. When you start the application with the “make” command, this file will be created containing the configuration to start the test runner or not. If you want to know more about this, take a look at the Makefile file in the project root. The Makefile requires bin/titanium.sh script to run.
- SampleApp/Resources/test/tests.js contains the test startup code. You will have to add code to include all your test scripts in this file.
- SampleApp/Resources/test/test_main.js is a sample file that contains the actual tests. You can (should) create as many files as you want, just remind to import all the modules on tests.js.
If you want more info about how to use Makefiles in your Titanium Mobile projects, please take a look at my blog post about it.
If you want to see how I use titanium-jasmine on a real production project, please take a look at Yahoo! Meme’s source code on GitHub.
If you have any other questions, please contact me through Twitter or e-mail.
titanium-jasmine is licensed under Apache Public License (Version 2). See LICENSE for more details.
Developed by Guilherme Chapiewski.