Add WorkManagerTestRule.

This commit is contained in:
Isira Seneviratne 2021-01-06 05:22:23 +05:30
parent 7c81b1ad15
commit ab8e7935b0
4 changed files with 62 additions and 2 deletions

View File

@ -135,6 +135,10 @@ android {
}
}
ext {
work_version = '2.4.0'
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
@ -145,7 +149,7 @@ dependencies {
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.palette:palette:1.0.0'
implementation 'androidx.work:work-runtime:2.4.0'
implementation "androidx.work:work-runtime:$work_version"
implementation 'com.google.android.material:material:1.1.0'
@ -177,6 +181,7 @@ dependencies {
testImplementation 'org.hamcrest:hamcrest:2.2'
testImplementation 'org.bouncycastle:bcprov-jdk15on:1.65'
androidTestImplementation 'androidx.arch.core:core-testing:2.1.0'
androidTestImplementation 'androidx.test:core:1.3.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
@ -184,6 +189,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation "androidx.work:work-testing:$work_version"
}
checkstyle {

View File

@ -0,0 +1,35 @@
package org.fdroid.fdroid;
import android.app.Instrumentation;
import android.content.Context;
import android.util.Log;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.work.Configuration;
import androidx.work.WorkManager;
import androidx.work.testing.SynchronousExecutor;
import androidx.work.testing.WorkManagerTestInitHelper;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
public class WorkManagerTestRule extends TestWatcher {
private Context targetContext;
private Context testContext;
private Configuration configuration;
private WorkManager workManager;
@Override
protected void starting(Description description) {
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
targetContext = instrumentation.getTargetContext();
testContext = instrumentation.getContext();
configuration = new Configuration.Builder()
.setMinimumLoggingLevel(Log.DEBUG)
.setExecutor(new SynchronousExecutor())
.build();
WorkManagerTestInitHelper.initializeTestWorkManager(targetContext, configuration);
workManager = WorkManager.getInstance(targetContext);
}
}

Binary file not shown.

View File

@ -63,6 +63,7 @@
<trusted-key id="7f36e793ae3252e5d9e9b98fee9e7dc9d92fc896" group="com.google.errorprone"/>
<trusted-key id="7faa0f2206de228f0db01ad741321490758aad6f" group="org.codehaus.groovy" name="groovy-all" version="2.4.15"/>
<trusted-key id="8254180bfc943b816e0b5e2e5e2f2b3d474efe6b" group="it.unimi.dsi" name="fastutil" version="7.2.0"/>
<trusted-key id="8756c4f765c9ac3cb6b85d62379ce192d401ab61" group="org.jetbrains.kotlinx"/>
<trusted-key id="90ee19787a7bcf6fd37a1e9180c08b1c29100955">
<trusting group="com.squareup" name="javawriter"/>
<trusting group="com.squareup" name="javawriter" version="2.1.1"/>
@ -86,7 +87,10 @@
<trusted-key id="c7be5bcc9fec15518cfda882b0f3710fa64900e7" group="com.google.auto.value"/>
<trusted-key id="cacfbd4755a2fc78709bdd92be096e29edb8d141" group="net.sf.proguard"/>
<trusted-key id="cb3190ca7842439e57f3712e44ce7bf2825ea2cd" group="com.ibm.icu" name="icu4j" version="53.1"/>
<trusted-key id="cc4483cd6a3eb2939b948667a1b4460d8ba7b9af" group="org.mockito" name="mockito-core" version="3.3.3"/>
<trusted-key id="cc4483cd6a3eb2939b948667a1b4460d8ba7b9af">
<trusting group="org.mockito" name="mockito-core" version="3.3.3"/>
<trusting group="org.mockito" name="mockito-core"/>
</trusted-key>
<trusted-key id="cd5464315f0b98c77e6e8ecd9daadc1c9fcc82d0">
<trusting group="commons-io"/>
<trusting group="commons-cli"/>
@ -166,6 +170,11 @@
<sha256 value="c0c4ed0160cd2ca18390015de8b392b697c173327c6b2c0947d4e62f6958c05d" origin="Generated by Gradle because artifact wasn't signed"/>
</artifact>
</component>
<component group="androidx.arch.core" name="core-testing" version="2.1.0">
<artifact name="core-testing-2.1.0.aar">
<sha256 value="c57ffade2a9a844bd62b4f4c3916fad5e09e9f24cceba27e932c25bb7a6d1d8f" origin="Generated by Gradle because artifact wasn't signed"/>
</artifact>
</component>
<component group="androidx.asynclayoutinflater" name="asynclayoutinflater" version="1.0.0">
<artifact name="asynclayoutinflater-1.0.0.aar">
<sha256 value="f7eab60c57addd94bb06275832fe7600611beaaae1a1ec597c231956faf96c8b" origin="Generated by Gradle because artifact wasn't signed"/>
@ -648,6 +657,16 @@
<sha256 value="7801441cb973fb007ef311d3db35c3b3c9d011cef890357e7ca33890833354e5" origin="Generated by Gradle because artifact wasn't signed"/>
</artifact>
</component>
<component group="androidx.work" name="work-runtime-ktx" version="2.4.0">
<artifact name="work-runtime-ktx-2.4.0.aar">
<sha256 value="290d2e9c1a22388b3f0c3dbc204a6176f8c49174126de884820befa83899f129" origin="Generated by Gradle because artifact wasn't signed"/>
</artifact>
</component>
<component group="androidx.work" name="work-testing" version="2.4.0">
<artifact name="work-testing-2.4.0.aar">
<sha256 value="dc1d9f743c59ee08c605aa924fc20819b6a0b734338e0a95af1943c3cd806e23" origin="Generated by Gradle because artifact wasn't signed"/>
</artifact>
</component>
<component group="antlr" name="antlr" version="2.7.7">
<artifact name="antlr-2.7.7.jar">
<sha256 value="88fbda4b912596b9f56e8e12e580cc954bacfb51776ecfddd3e18fc1cf56dc4c" origin="Generated by Gradle because artifact wasn't signed"/>