Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Unit Test Not Reporting Failing with fail()

I've written a unit test that simply extends TestCase and I have the following:

public class MetricParserTests extends TestCase {

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testFailure() {
        fail("This needs to fail");
    }
}

When I run my tests using ant test or adb shell am instrument I get the following results:

... [exec] OK (1 tests) ...

I'd expect to see a failure on the command line.

like image 694
Gregg Avatar asked Nov 24 '22 08:11

Gregg


1 Answers

I believe I know what the issue is. I was able to reproduce the issue and solve it. The command you use does not rebuild and re-install your test project onto a device. When you call ant test it will just execute the tests which are already installed on that device.

What you need to call is the three commands in your test project's directory:

ant debug
ant installd
ant test

Then all tests will be rebuild and re-installed and latest tests will be executed. If you don't call debug and installd, the changes you did to the tests do not get applied.

like image 171
sergej shafarenka Avatar answered Dec 06 '22 08:12

sergej shafarenka