简体   繁体   中英

Parametrized android tests with different sets of data

Currently i'm researching a ways of writing unit and integration tests for android apps. I have so confused that there is absent a possibility to provide a set of parameters directly to the method like JUnitParams library does. So i have several questions:

  1. Is there a way to combine AndroidJUnit4 and JUnitParamsRunner to combine an access to android classes ( like Rect) with parametrized methods?
  2. If not, what is the best way of architecture organization of tests? By example i have a set of invalid data, which should lead to exception and a set of valid data ( threshold values and regular) and two methods to test it. Should i create two classes for this purpose? (Because it is not possible to provide different sets of data, which will be used in one class without some duct tape, like enum parameter etc.)

I'm not familiar with JUnitParamsRunner but I'd recommend creating multiple test methods, one for each outcome you wish to test. Each class you are testing should have it's own test class and the code required for testing would be contained within that (aside from generic helpers).

This is generally how my tests look (basically Given, When, Then):

public void testExample() throws Exception {
    // setup test data

    // do the actual method calls

    // assert the expected outcome
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM