-
Notifications
You must be signed in to change notification settings - Fork 3
Testing
We should have more tests...
For testing operations that require functioning repositories, we have a general mocking setup here:
Include test data in app/src/test/res/
e.g. app/src/test/res/dining_halls.json
This particular file is a JSON ripped from HTTP GET'ing from BM REST API (BMService). Similar data can be fetched from Firestore for testing purposes. It may also be useful to create data files with faulty/malformed data.
As for mocking repositories, we have in this case:
/**
* Mock a DiningHall repo
*/
public DiningHallTestRepository() {
Gson gson = new Gson();
DiningHallTransformer transformer = new DiningHallTransformer();
try {
Type listInfra = new TypeToken<List<com.asuc.asucmobile.infrastructure.models.DiningHall>>() {}.getType();
URL url = this.getClass().getClassLoader().getResource("dining_halls.json");
List<com.asuc.asucmobile.infrastructure.models.DiningHall> infraDiningHalls = gson.fromJson(new FileReader(url.getFile()), listInfra);
diningHalls = transformer.diningHallListInfraDomainTransformer(infraDiningHalls);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.err.println("File not found");
}
}
First line creates a GSON for inflating JSON data to POJO. We also need a transformer from Infrastructure models (assuming that's the format of the data, which it should be if it's ripped from our actual data sources). Next few lines are a hacky way of reading in the JSON file from resources, and transforming.
- Home
- Controllers
- Dagger
- Domain
- Infrastructure
- Utilities
- Values
- Functional Docs