Question: I have seen several post regarding making a build in Jenkins fail if the unit test execution fail (e.g. this [one](https://stackoverflow.com/questions/6681880/how-to-make-jenkins-display-fail-if-one-of-the-ant-tests-fail)). It turns out that by default Jenkins reports builds with failing tests as `unstable` and some people do not like that. This, however, will be perfectly fine for me. I just want to be able to easily differentiate builds with passing tests from such with failing tests. 

And here is the catch: **I am developing for Android** so my build is configured following [this page](https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project). Basically the tests are run with the following command:

```
ant all clean emma debug install test

```

As result coverage report is generated and published in Jenkins.

All posts I have read about configuring the Jenkins result according to tests results
were dealing with ant task manipulation. However, if we look at the android `build.xml` the Android tests are run with adb command: `adb shell am instrument ...`. I don't know how to configure this command to print the tests results. It can be configured to print the coverage report. I have already done that, but was never able to make the build fail according to the coverage report.

I hope somebody else also faced the same problem and managed to solve it. Any guidance will be most appreciated.

Answer: 
You have two options:

Either use the `AsyncTask`'s method `get(long timeout, TimeUnit unit)` like that:

```
task.get(1000, TimeUnit.MILLISECONDS);

```

This will make your main thread wait for the result of the `AsyncTask` at most 1000 milliseconds (as per @user1028741 comment: actually there is also infinetly waiting method - [`AsyncTask#get()`](http://developer.android.com/reference/android/os/AsyncTask.html#get%28%29) which might also do the work for you in some cases).

Alternatively you can show a progress dialog in the async task until it finishes. See this [thread](https://stackoverflow.com/a/4538370/1108032) (No need for me to copy past the code). Basically a progress dialog is shown while the async task runs and is hidden when it finishes.

You have even third option:" if `Thread` is sufficient for your needs you can just use its `join` method. However, if the task is taking a long while you will still need to show a progress dialog, otherwise you will get an exception because of the main thread being inactive for too long.
try using

```
if (AppHelper.isOnline(this))
        {
            while(!task.isCancelled()){
               // waiting until finished protected String[] doInBackground(Void... params)          
              } 
            intent = new Intent(this, OrdineCreaActivity.class);
            this.startActivityForResult(intent, R.id.buttonPagamenti);
        }    

```

For more information read <http://developer.android.com/reference/android/os/AsyncTask.html>