Book Image

Learning Android Application Testing

Book Image

Learning Android Application Testing

Overview of this book

Table of Contents (16 chapters)
Learning Android Application Testing
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing Fest


Another weapon for our testing arsenal is better testing assertions. Have you noticed how sometimes stacktraces for failed tests are really unfriendly and/or mystically wrong? They give you little information about the real failure and you end up confused, having to read the entire source to fathom out how to fix the problem.

As an example, look at this assertion:

org.junit.Assert.assertEquals(3, myList.size());

We are asserting that a collection of objects after some task has a size of three, look at our error message when the test fails:

java.lang.AssertionError: 
Expected :3
Actual   :2

Ok, that kind of makes sense, but it's a bit abstract. What item is missing from our list? I am going to have to run the tests again to find out, or I could add a custom error message:

assertEquals("List not the correct size " + myList, 
3, myList.size());

Giving me the error message:

java.lang.AssertionError: List not the correct size [A, B] 
Expected :3
Actual   :2

That error message is much...