forked from artem-zinnatullin/qualitymatters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QualityMattersIntegrationRobolectricTestRunner.java
45 lines (37 loc) · 1.7 KB
/
QualityMattersIntegrationRobolectricTestRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.artemzin.qualitymatters;
import android.support.annotation.NonNull;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.lang.reflect.Method;
// Custom runner allows us set config in one place instead of setting it in each test class.
public class QualityMattersIntegrationRobolectricTestRunner extends RobolectricTestRunner {
// This value should be changed as soon as Robolectric will support newer api.
private static final int SDK_EMULATE_LEVEL = 23;
public QualityMattersIntegrationRobolectricTestRunner(@NonNull Class<?> klass) throws Exception {
super(klass);
}
@Override
public Config getConfig(@NonNull Method method) {
final Config defaultConfig = super.getConfig(method);
return new Config.Implementation(
new int[]{SDK_EMULATE_LEVEL},
defaultConfig.manifest(),
defaultConfig.qualifiers(),
defaultConfig.packageName(),
defaultConfig.abiSplit(),
defaultConfig.resourceDir(),
defaultConfig.assetDir(),
defaultConfig.buildDir(),
defaultConfig.shadows(),
defaultConfig.instrumentedPackages(),
QualityMattersUnitTestApp.class, // Notice that we override real application class for Unit tests.
defaultConfig.libraries(),
defaultConfig.constants() == Void.class ? BuildConfig.class : defaultConfig.constants()
);
}
@NonNull
public static QualityMattersApp qualityMattersApp() {
return (QualityMattersApp) RuntimeEnvironment.application;
}
}