Не используется IsolationActivity через AndroidBenchmarkRunner - PullRequest
0 голосов
/ 04 мая 2020

Я пытаюсь попробовать библиотеку Jetpack Benchmark Android и, похоже, не могу обойти эту ошибку. Перепробовал все, что мог придумать, был бы признателен за любую помощь, чтобы этот простой пример работал.

java.lang.AssertionError: ERRORS (not suppressed): ACTIVITY-MISSING
(Suppressed errors: DEBUGGABLE EMULATOR UNLOCKED)

WARNING: Not using IsolationActivity via AndroidBenchmarkRunner
AndroidBenchmarkRunner should be used to isolate benchmarks from interference
from other visible apps. To fix this, add the following to your module-level
build.gradle:
android.defaultConfig.testInstrumentationRunner
= "androidx.benchmark.junit4.AndroidBenchmarkRunner"

Я следовал примеру руководства здесь , а мой defaultConfig содержит:

testInstrumentationRunner 'androidx.benchmark.junit4.AndroidBenchmarkRunner'
// Suppressing errors I can ignore while I'm testing. Unfortunately, suppressing 
// the ACTIVITY-MISSING error causes runtime crashes
testInstrumentationRunnerArgument 'androidx.benchmark.suppressErrors', 'EMULATOR,DEBUGGABLE,UNLOCKED'

, а мои зависимости содержат:

    androidTestImplementation 'androidx.annotation:annotation:1.1.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:core:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.benchmark:benchmark-junit4:1.0.0'

Мой контрольный код выглядит следующим образом:

import android.util.Log;

import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class BenchmarkTest {

    @Rule
    public BenchmarkRule benchmarkRule = new BenchmarkRule();

    @Test
    public void log() {
        final BenchmarkState state = benchmarkRule.getState();
        while (state.keepRunning()) {
            Log.d("LogBenchmark", "the cost of writing this log method will be measured");
        }
    }
}
...