mardi 2 juin 2015

InstrumentationTestCase - catch a fail before tearDown

I'm using the InstrumentationTestCase class to conduct my tests for my Android app that uses Bluetooth.

However, due to the nature of Bluetooth, some failures result in a messy cleanup that influence other test cases. Is there a way to catch a failure before the program calls tearDown()? The reason I can't put all the cleanup in teardown is because there could be cerain commands that aren't allowed in current states (connecting while disconnecting, etc).

Basically what I'm trying to do is the following:

public void test_A() {
    try {
       doSomething();
       doSomethingElse();
       doSomethingBad();
    catch(Failure f) {
        properCleanup();
    }
}

void doSomethingBad() { fail(); } //not an exception

Thanks!

Aucun commentaire:

Enregistrer un commentaire