Search in sources :

Example 1 with AndroidSandbox

use of org.robolectric.internal.AndroidSandbox in project robolectric by robolectric.

the class RobolectricTestRunner method beforeTest.

@Override
protected void beforeTest(Sandbox sandbox, FrameworkMethod method, Method bootstrappedMethod) throws Throwable {
    AndroidSandbox androidSandbox = (AndroidSandbox) sandbox;
    RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method;
    PerfStatsCollector perfStatsCollector = PerfStatsCollector.getInstance();
    Sdk sdk = roboMethod.getSdk();
    perfStatsCollector.putMetadata(AndroidMetadata.class, new AndroidMetadata(ImmutableMap.of("ro.build.version.sdk", "" + sdk.getApiLevel()), roboMethod.resourcesMode.name()));
    Logger.lifecycle(roboMethod.getDeclaringClass().getName() + "." + roboMethod.getMethod().getName() + ": sdk=" + sdk.getApiLevel() + "; resources=" + roboMethod.resourcesMode);
    if (roboMethod.resourcesMode == ResourcesMode.LEGACY) {
        Logger.warn("Legacy resources mode is deprecated; see" + " http://robolectric.org/migrating/#migrating-to-40");
    }
    roboMethod.setStuff(androidSandbox, androidSandbox.getTestEnvironment());
    Class<TestLifecycle> cl = androidSandbox.bootstrappedClass(getTestLifecycleClass());
    roboMethod.testLifecycle = ReflectionHelpers.newInstance(cl);
    AndroidManifest appManifest = roboMethod.getAppManifest();
    roboMethod.getTestEnvironment().setUpApplicationState(bootstrappedMethod, roboMethod.getConfiguration(), appManifest);
    roboMethod.testLifecycle.beforeTest(bootstrappedMethod);
}
Also used : AndroidSandbox(org.robolectric.internal.AndroidSandbox) AndroidManifest(org.robolectric.manifest.AndroidManifest) Sdk(org.robolectric.pluginapi.Sdk) PerfStatsCollector(org.robolectric.util.PerfStatsCollector)

Aggregations

AndroidSandbox (org.robolectric.internal.AndroidSandbox)1 AndroidManifest (org.robolectric.manifest.AndroidManifest)1 Sdk (org.robolectric.pluginapi.Sdk)1 PerfStatsCollector (org.robolectric.util.PerfStatsCollector)1