Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test Evernote's Android Jobs?

How do I test Jobs created with Android-Job library? Any ideas on unit testing, instrumented testing or even manual testing are appreciated, I just want to check if it works as expected.

To be specific, I have a job that performs an HTTP request every N hours:

package com.kondenko.yamblzweather.job;


import android.support.annotation.NonNull;

import com.evernote.android.job.Job;
import com.evernote.android.job.JobRequest;
import com.kondenko.yamblzweather.model.entity.WeatherData;
import com.kondenko.yamblzweather.ui.weather.WeatherInteractor;
import com.kondenko.yamblzweather.utils.SettingsManager;

import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

public class UpdateWeatherJob extends Job {

private WeatherInteractor interactor;
private String cityId;
private String units;
private long refreshRateHr;

// Do not delete, needed for job creation
public static final String TAG = "UpdateWeaterJob";

@Inject
public UpdateWeatherJob(WeatherInteractor interactor, SettingsManager settingsManager) {
    this.interactor = interactor;
    this.cityId = settingsManager.getSelectedCity();
    this.units = settingsManager.getSelectedUnitValue();
    this.refreshRateHr = settingsManager.getRefreshRate();
}

@NonNull
@Override
protected Result onRunJob(Params params) {
    WeatherData data = interactor.getWeather(cityId, units).blockingGet();
    return data != null ? Result.SUCCESS : Result.FAILURE;
}


public void buildJobRequest(String name) {
    new JobRequest.Builder(UpdateWeatherJob.TAG)
            .setPeriodic(TimeUnit.HOURS.toMillis(refreshRateHr))
            .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
            .setRequirementsEnforced(true)
            .setPersisted(true)
            .build()
            .schedule();
}

}
like image 584
Vladimir Kondenko Avatar asked Jul 15 '17 23:07

Vladimir Kondenko


People also ask

How to diagnose Evernote Android-job?

Both Evernote Android-Job and Firebase JobDispatcher are now in maintenance only mode and they both suggest to use jetpack's WorkManager for these kind of jobs. Android Jetpack WorkManager made it slightly easier to diagnose. After that you can WorkManager will dump information in ADB Logcat which you can observe by entering.

Is there a JobScheduler for Android jobs?

It provides a JobScheduler-compatible API that works on all recent versions of Android (API level 9+) that have Google Play services installed. I hope this helped. Both Evernote Android-Job and Firebase JobDispatcher are now in maintenance only mode and they both suggest to use jetpack's WorkManager for these kind of jobs.

What is the best way to schedule background jobs on Android?

Even better use the firebase job dispatcher library. The Firebase JobDispatcher is a library for scheduling background jobs in your Android app. It provides a JobScheduler-compatible API that works on all recent versions of Android (API level 9+) that have Google Play services installed.

How do I find the job_ID of an Android application?

You can do this by using the adb shell cmd jobscheduler run command, (requires Android 7.1 or higher). For example, your packagename is com.foo.bar.application and the JOB_ID was 1.


1 Answers

We at Evernote test jobs the following way:

  • Unit tests -> We tend to extract the logic into actions, similar to presenters in a MVP setup. This removes Android dependencies and the actions are unit testable.
  • QA -> We have QA options to trigger jobs manually. This way our QA team can verify that the job produces the correct output
  • Verifying timing -> There we rely on the logs.

You also should take a look at these slides. ADB can be really helpful to verify curtain assumptions.

like image 121
vRallev Avatar answered Oct 07 '22 01:10

vRallev