Instant mock testing with PowerMock - Book Review

A few weeks ago someone from Packt publishing contacted me offering me a free copy of Instant mock testing with PowerMock if I accepted to write a review afterwards. Since I’ve been lately suffering with Unit Testing on Android I accepted and here is my review.

The book is really short and focused, which made it a very fast ready. I like this because I don’t really want to spend a lot of time learning how to mock something, it should be really straight forward.

Read More

Big O Notation

Big O notation is a way to represent how well an algorithm scales as the amount of data involved increases. I will go over some examples of the most common orders and try to explain what each one means:

O(1)

This means that the algorithm will perform the same way no matter how long the data set is. This is usually the case for hash tables. Here is an example of an O(1) algorithm:

1
2
3
4
5
var myArray = [];

function addToArray(num) {
  myArray.push(num);
}
Read More

Increase number of files Command-T will search

I was having a problem with Vim’s Command-T plugin, where it didn’t find some files. Searching through the documentation I found the problem was that Command-T will search a maximum of 10,000 files by default. This can be changed by adding this to your .vimrc:

1
2
" Increase the number for files Command-T will search "
let g:CommandTMaxFiles=50000
Read More

Running simple web server on a folder

There are multiple web servers out there that allow you to do almost anything you can think of, but what I needed was to run a simple web server that would serve the files in a folder. Python allows you to do this very easily:

1
python -m SimpleHTTPServer
Read More

Command line task manager for Linux

I found this little gem because I wanted to see how my raspberry pi was handling one running process. You can use the top command to see the running processes:

1
top

You will probably have a bunch of zombie processes you don’t care about. To omit those use:

1
top -i
Read More

Writing unit test for Android with Easymock

I already wrote a post about how to create a test suite for Android, but while trying more complex tests I noticed that a lot of things are not as easy as I would have expected. Unit testing Java is different that unit testing JavaScript, but unit testing Android is even a little harder. The problem with Android is that a lot of things depend on the Activity life cycle and most of the methods have been made final so they are impossible to mock.

Alternatives

Easymock wasn’t my first alternative. My first choice was Robolectric because I heard a lot of people say good things about it, the problem is that it has very little documentation and most of it is specific for eclipse. They also have a sample project but I wasn’t able to make it work. I also tried Mockito but I wasn’t able to make it work with my project. The reason I chose Easymock is because it was really easy to make it work and it seems to have a lot of support and documentation.

Read More

Android emulator acceleration

The android emulator if used as it comes from the package is pretty slow, so it is good to know that there are ways to make it a little faster.

Graphics acceleration

To use this feature you need to have these versions installed:

  • Android SDK Tools, Revision 17 or higher
  • Android SDK Platform API 15, Revision 3 or higher

You can verify that you meet these requirements by launching the android app:

1
/path/to/android-sdk/tools/android
Read More

Introduction to Compass

Compass describes itself as an open source CSS authoring framework. For me, it is a tool that helps me organize my CSS and create sprites easily.

To install compass you need to have ruby on your system, which I trust you can do by yourself. Once you have ruby installed you need to use these commands:

1
2
gem update --system
gem install compass

Next you will want to create a compass project. Go to your project folder and use this command:

1
compass create <project-name>
Read More

Trasfering files via SSH

I sometimes need to transfer files from one computer to another using SSH and I always forget how to do it so I decided to write a short post as a reminder.

To copy a file from one computer to another we use the scp command, which is very easy to use:

1
scp file.txt <remote user>@<some domain or ip>:<remote path>

The cool thing is that you can copy from the remote computer to your local computer inverting the order:

1
scp <remote user>@<some domain or ip>:<remote path to file> /home/adrian/

Finally, if you want to copy a folder with all it’s content you need to add a -r flag.

Read More

Hooking your github project to Travis-CI

I have a little open source project that I am trying to slowly improve. One of the steps I’m taking to do this is to add some tests and code static analysis. If something is running correctly I don’t want regressions so I need to plug it to CI so it runs for every commit. A lot of people are using Travis so I decided to give it a try. The first steps can be found at Travis’ getting started page.

My project is a PHP project but it needs node to run grunt tasks so I was worried about not being able to specify two programming languages in the yml file. Luckily Travis includes a version of node on all VMs no matter what type of project you are using, so I could freely use npm and grunt:

1
2
3
4
5
language: php
php:
  - "5.4"
before_script: "npm install"
script: "./node_modules/grunt-cli/bin/grunt"

I also found that if you have a very specific requirement you can even use apt-get to download dependencies and then you will be able to use it as part of your task.

Read More