I’ve recently been looking at unit testing some isolated components for a mobile application I’m working on. Part of the application is a calculations engine which I wanted to test against a known set of sample data and results.
There have been many attempts through the community at putting widely accepted testing frameworks throughout the last few years, but none felt too akin to what I wanted or how I wanted it to work. Most of the testing frameworks out there such as
timocha run within the application via a simulator and this was something I wanted to avoid.
For version control I use both Github for personal projects and then Gitlab at work and for my larger personal projects. I wanted a solution that could run within Gitlab’s CI runner – which I use Docker.
I began by creating a
Dockerfile which included the things needed to build an application. There were a few road blocks in the way. The image needed to have node, npm, Oracle Java 8, android-idk-linux and a few npm packages such as
appc command will require a username and password to login to to Appcelerator’s platform to fetch an SDK and produce a build – this wasn’t ideal. The
appc tool won’t run under the
root user (for good reason) which also meant employing
runuser a few times to get commands to run.
A few very helpful conversations with Adam Paxton highlighted the useful
tisdk npm package which will fetch and install SDKs and the open source
ti NPM package can perform the open source version of
appc which includes producing a build. You’ll also need to install some gcc libraries as well (they’re in the Dockerfile).
The producing a build part is needed with
tiunit so that you can correctly include any alloy resources that you need (in my case, I had used
alloy/moment in a few places which I ended up mocking instead. For reference, you can build your application using (adjust for platform you’re using):
appc run -p android -b
In the end, I managed to get my
tiunit tests running, I’ll follow up with a sample application and test case for you to follow along with.
You can use the image from Dockerhub at hellossx/appcelerator-ci which is built automatically from the Github repo ssx/docker-appcelerator-ci. I used the following
.gitlab-ci.yml configuration to have it run my tests:
- npm install
- tisdk install 6.0.3.GA
- ti build -p android -b
- npm test
If you prefer that as a gist, you can view it here.
- Hyperloop is a no-no using this method, without introducing your Appcelerator username/password into the scripts.
- Introducing Appcelerator username/passwords would be trivial using Gitlab’s secret variables within their CI.