Albert Rosa It's not what you say it's how you say it

11May/120

Android Testing for Exception With Robolectric.

No Gravatar

I've been wanting to test runtime errors that I throw when certain criterias have not been met, Fairly easy to do with JUNIT itself but I found it difficult to use the expected annotation since when testing with Robolectric you receive a runtime exception first then drill into the cause of the exception.

here's how I found my way around this issue

@Test
public void testNullPointerWithURL() throws Exception{
try{
sample.execute();
fail("Should fail will Runtime Exception");
} catch (java.lang.RuntimeException e){
assertThat(e.getCause().getClass().getName(), CoreMatchers.is(NullPointerException.class.getName()));
}
}

 

sample.execute throws a NullPointerException. I wanted to validate in test that the exception was actually being executed.

 

Share
Filed under: Android, Testing No Comments
3Apr/120

Faster Native Android Development with Roboguice

No Gravatar

To this date all of the applications I have release and demoed have been written entirely from scratch using no 3rd party libraries and used a full Test Driven Development pattern that I'm used to ( write it, run it, works Ok, don't work Fix it).  Personally I do recommend developers who are starting with android development to do so without any assistance with Roboguice, just so you can see what it actually entails and what roboguice actually does for you.

So Roboguice, you are wonder what it is, well its an injection based library for android. I have converted one of my prototypes to use roboguice and I must say its much cleaner than before but there isn't much of a difference in performance so it fits in just right. It's fairly simple to follow and use, here's the link to robo guice ( http://code.google.com/p/roboguice/ ) and with that you will also need to install guice ( http://code.google.com/p/google-guice/ ).  Roboguice extends guice for Android development. Again Guice is a injection framework for java 5 and above.

I do recommend the use of these libraries for all application development for ease of use and improvement in code read-ability. Give it a shot and see how it compares to your previous works of art.

Share
Filed under: Android, Resource No Comments
3Apr/120

Android simple Game tutorial

No Gravatar

I have been thinking of a way to expand my knowledge of game development towards Android, so far I've created small simple games that respond to the normal android lifecycle and no real Game Mechanics.

I have found a few resources on line that started tutorials around some Action Type of game development I just wanted to share the knowledge:

http://www.javacodegeeks.com/2011/07/android-game-development-create-project.html

 

Share

Albert Rosa is using WP-Gravatar