Giter Site home page Giter Site logo

unit-test-titanium-alloy-project's Introduction

#My approach to fully automate unit tests in Titanium Alloy projects.

First some notes:

I couldn't find a way to integrate unit tests in Alloy projects AND automate that using a Continuous Integration build server. This is my first approach to integrate unit tests in Titanium Alloy projects. I've never ever done anything with Titanium before, but I hope this information is helpful for some of you.

After some researching and asking (http://developer.appcelerator.com/question/146254/titanium-30--unit-testing--jenkins and the Titanium Google Group) I was inspired by a presentation of https://github.com/tonylukasavage at Codestrong 2012 (http://www.slideshare.net/appcelerator/codestrong-2012-breakout-session-testing-best-practices-unit-and-functional-automation)

I borrowed behave.js from: https://github.com/appcelerator/Codestrong/blob/master/app/lib/behave.js. I modified this version to let it create a JUnit XML report file. The code needs some shaving, but it should work fine.

Behave.js runs the tests (specs) while the app runs in the simulator so mocking the Titanium API isn't needed. Of course this approach has some downsides as well, but I find this useful.

Please note the JUnit XML file is written to the temp folder on my Mac. If you're not on a Mac, you need to change that location so the XML file can be written.

##Let's go

1) Create a new Titanium Alloy project

2) Integrate /app/lib/behave.js and call him from alloy.js

See changeset: https://github.com/denvers/unit-test-titanium-alloy-project/commit/cf653d746b4b9c46a278921fc68e143401d9b9ef

3) Create a test (called a spec) in /app/assets/spec/

4) Let behave.js run your spec by adding a require in your alloy.js file

(3+4) See changeset: https://github.com/denvers/unit-test-titanium-alloy-project/commit/c98d7fbcd2e8d32eefed683e2e6783efa4a10ed0

When compiling your app, you'd see in your console that the JUnit XML file is written to /tmp/junit-buildresults.xml (http://cl.ly/image/2J2e1y3H2t3b)

##Now the automation part…

I use Jenkins as a Continuous Integration buildserver. Other buildservers who are able to interpret JUnit XML files should work also.

My code is pushed to a private Github repository. You should configure your Jenkins job to let Jenkins read your project files. I bet you know how to fix this yourself ;-)

1) I created a job for running the tests in Jenkins. The interesting parts are:

a) A buildstep with some magic commands to build the app and have the unit tests executed:

cd ${WORKSPACE}/unit-testing-alloy-projects **# ENTER YOUR PROJECT FOLDER**
titanium clean
titanium build --platform ios --deploy-type test --log-level debug &
sleep 30
mv /tmp/junit-buildresults.xml ${WORKSPACE}/unit-testing-alloy-projects **# ENTER YOUR PROJECT FOLDER**
sleep 3
killall "iPhone Simulator"

b) Add a post build action which tells Jenkins the location of the JUnit buildresults XML file; Publish JUnit report and enter the relative path to that file:

Test report XMLs: unit-testing-alloy-projects/junit-buildresults.xml

That's it! This should do the trick. You are able to fully automate building your apps using a Continuous Integration approach

I hope this will help some of you out. Get in touch with me at Twitter: @webvakker

unit-test-titanium-alloy-project's People

Contributors

denvers avatar

Watchers

Alban Jubert avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.