Tuesday, May 22, 2012

Analysing Android test frameworks


Searching for some Android test frameworks, I found, as most relevant, Roboeletric, Robotium and Calculon.

So I had to look inside them to define which one would fit my needs.

Roboeletric 

http://pivotal.github.com/robolectric/eclipse-quick-start.html
looks like the best one to use, because it runs tests in less time than the others. It runs in JVM without the need to use an emulator or a device. Besides it has clean and meaningful syntax and provides some kind of mock through shadow objects.

Good presentation:
http://www.slideshare.net/joemoore1/tdd-android-applications-with-robolectric

Robotium 

http://code.google.com/p/robotium/
is nice too, but it's slow because it needs an emulator or a device to run tests. It's the best option to run some specific tests that Roboeletric doesn't implement and to run on real devices. It shows the clicks on screen, edit fields being filled and screen navigation, which make things more realistic.

Reference:
http://www.slideshare.net/hugojosefson/robotium-at-android-only-2010-0929

Calculon

https://github.com/kaeppler/calculon
http://brainflush.wordpress.com/2010/01/10/introducing-calculon-a-java-dsl-for-android-activity-testing/
on the other hand, has it's own syntax to make more semantical tests , more readable. It also needs an emulator or a device to run tests, making it slow too.

Great presentation:
http://www.slideshare.net/matthiaskaeppler/calculon



Which I'll use


Roboeletric will be the one I'll choose, mostly because I'm doing TDD and really like faster response.

Monday, May 7, 2012

Analysing ORMs for Android



ActiveAndroid

https://www.activeandroid.com/
-Verbose
--Need to declare everything with annotations
--Query with too much method calls
-$19.90 / developer

android-active-record

http://code.google.com/p/android-active-record/
+No model configuration
+Annotation only when not following convention
-Database configuration before every access to database
-No relations support
-CRUD methods in _db object
--Manager like JPA EntityManager

Androrm

http://androrm.the-pixelpla.net/
-Always need to pass the ApplicationContext
-Need to call object's method that retrieves a QuerySet, where query methods are implemented
--Ex:
    Author.objects(getApplicationContext()).all();
+Create, update and delete methods called directly from Models (although passing applicationContext)
+Relations support
-Verbose model configuration
--Inspired by Django
--Ex:
    protected CharField mTitle;
    protected ForeignKeyField mAuthor;
   
    public Book() {
        super();
       
        mTitle = new CharField(80);
        mAuthor = new ForeignKeyField(Author.class);
    }
 

ORMLite

http://ormlite.com/sqlite_java_android_orm.shtml
-Uses dao for each model with crud methods
-Lack of documentation for Android
-Model configuration with annotations
--Ex:
    // you get the SQLiteOpenHelper from your Android Activity
    ConnectionSource connectionSource =
         new AndroidConnectionSource(sqliteOpenHelper);
    Dao accountDao =
         BaseDaoImpl.createDao(connectionSource, Account.class);
    TableUtils.createTable(connectionSource, Account.class);

    String name = "Jim Smith";
    Account account = new Account(name, "_secret");
    if (accountDao.create(account) != 1) {
         throw new Exception("Failure adding account");
    }
    Account account2 = accountDao.queryForId(name);
    connectionSource.close();

GreenDAO

http://greendao-orm.com/
-Lot of configuration
-It uses another app to create entities
+Relations support
-Programmatic model configuration
--EX:
    Entity user = schema.addEntity("User");
    user.addIdProperty();
    user.addStringProperty("name");
    user.addStringProperty("password");
    user.addIntProperty("yearOfBirth");
-Verbose query creation
--Ex:
    QueryBuilder qb = userDao.queryBuilder();
    qb.where(Properties.FirstName.eq("Joe"),
    qb.or(Properties.YearOfBirth.gt(1970),
    qb.and(Properties.YearOfBirth.eq(1970), Properties.MonthOfBirth.ge(10))));
    List youngJoes = qb.list();
 

Sugar

https://github.com/satyan/sugar
+Little configuration
-No relations support
-Need to pass context and class everytime
--Ex:
    # inserting values
    Note note = new Note(context, "Note 1");
    note.save();
    # query
    Note.findById(context, Note.class, 1);
    Note.find(context, Note.class, "title=?", new String[]{"Note 1"});
    # delete
    Note note = Note.findById(context, Note.class, 1);
    note.delete();
    # few more..
    Note.listAll(context, Note.class);
    Note.deleteAll(context, Note.class);
 

Orman

https://github.com/ahmetalpbalkan/orman
-No transaction
-Need to pass class everytime
+Few model configuration
+Create, update and delete methods called directly from Models
-Verbose query creation
--Ex:
    List students = Model.fetchAll(Student.class);

    String name = (String) Model.fetchSingleValue(ModelQuery.select()
                    .from(Student.class)
                    .orderBy("Student.gpa", "-Student.registrationDate")
                    .limit(1)
                    .selectColumn(Student.class, "name")
                    .getQuery());


Hadi

http://hadi.sourceforge.net/
-DAO
-Classes annotations
-Less used

 

Some comparison


  1. http://software-workshop.eu/content/comparing-android-orm-libraries-greendao-vs-ormlite
  2. http://www.ninthavenue.com.au/android-orm-jpa
  3. https://github.com/ahmetalpbalkan/orman/wiki/Why-orman-is-better-than-other-orms-for-you%3F


Which I'll use

As a Rails developer, I first tried to find something like ActiveRecord for Android. Actually I tried to create it first, then I thought that it should exists somewhere over the internet.

So I was looking for something easy to use and zero configuration, but as I tried to build it in Java, I saw that was impossible to do with Java what is done with Ruby, then I just discovered that many Frameworks.

At first, like I was searching for some ActiveRecord for Android, I found ActiveDroid and android-active-record, and a lot of others came during my research.

Finally, after creating this comparative post I decided to study deeper two of then: android-active-record and Sugar, just because they were simplest, and based in my original problem too, that was "How difficult is to add a new field in database and it show up on view".


That's it.

Edit: After studying both android-active-record and Sugar, I chose Sugar because of its zero configuration and simplicity.