Android Testing for Exception With Robolectric.
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.
#TNDO … Spartans 24/7/365
Just how it should be...
Take No Days Off #TNDO Apparel Promo from Greyskale Multimedia LLC on Vimeo.
COLORADO… YOU READY… CUZ THE SPARTANS ARE TAKING OVER!
That's right kids, Spartan Race is hitting Colorado. It's not just any spartan race it's the Spartan Military Race... Yours truly and My sister Will be taking on the course On May 5th... Cinco De Mayo.... TEAM Rice-N-Beans