Question

I am running tests with uiautomator. When I get to the end of my test, I need to test my results. My problem is of one test fails, the others will not be tested. I need them all to be tested regardless of the results of other test. This is my attempts:

public void testSomeUI() {
  ////lots of stuff

  assertEquals(///assertion///);
  assertEquals(///assertion///);
  assertEquals(///assertion///);
  ....and so on
}

Also I tried:

public void testSomeUI() {
  ////lots of stuff

 testValue1();
 testValue2();
 testValue3();
  ....and so on
}

  private void testValue1(){
   assertEquals(///assertion///);
}  
  private void testValue2(){
   assertEquals(///assertion///);
}   
  private void testValue3(){
   assertEquals(///assertion///);
} 
..and so on

If one fails, the last three won't run. Any suggestions? Thanks.

Was it helpful?

Solution

Problem is that once an assert fails, it breaks out of the method. That's why the rest don't get run.

Try using a test framework like JUnit (which UIAutomator appears to be built on). Then write one method per assert. That way will you not only get all asserts to run every time, you also break down the tests into suitably small sizes. If they're named properly, you may not need to debug at all, since you can tell by name of the failing test where the problem really is.

Here's a link to a tutorial for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top