Search in sources :

Example 1 with RobolectricTestRunner.defaultInjector

use of org.robolectric.RobolectricTestRunner.defaultInjector in project robolectric by robolectric.

the class RobolectricTestRunnerTest method shouldReportPerfStats.

@Test
public void shouldReportPerfStats() throws Exception {
    List<Metric> metrics = new ArrayList<>();
    PerfStatsReporter reporter = (metadata, metrics1) -> metrics.addAll(metrics1);
    RobolectricTestRunner runner = new SingleSdkRobolectricTestRunner(TestWithTwoMethods.class, RobolectricTestRunner.defaultInjector().bind(PerfStatsReporter[].class, new PerfStatsReporter[] { reporter }).build());
    runner.run(notifier);
    Set<String> metricNames = metrics.stream().map(Metric::getName).collect(toSet());
    assertThat(metricNames).contains("initialization");
}
Also used : MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) Result(org.junit.runner.Result) SdkCollection(org.robolectric.plugins.SdkCollection) PerfStatsReporter(org.robolectric.pluginapi.perf.PerfStatsReporter) ShadowProvider(org.robolectric.internal.ShadowProvider) ShadowLooper.shadowMainLooper(org.robolectric.shadows.ShadowLooper.shadowMainLooper) Configuration(org.robolectric.pluginapi.config.ConfigurationStrategy.Configuration) Handler(android.os.Handler) Looper(android.os.Looper) After(org.junit.After) Assert.fail(org.junit.Assert.fail) Method(java.lang.reflect.Method) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) StubSdk(org.robolectric.plugins.StubSdk) RunListener(org.junit.runner.notification.RunListener) AndroidTestEnvironment(org.robolectric.android.internal.AndroidTestEnvironment) Sdk(org.robolectric.pluginapi.Sdk) Set(java.util.Set) Description(org.junit.runner.Description) RobolectricFrameworkMethod(org.robolectric.RobolectricTestRunner.RobolectricFrameworkMethod) StandardCharsets(java.nio.charset.StandardCharsets) Failure(org.junit.runner.notification.Failure) LazyLoad(org.robolectric.annotation.experimental.LazyApplication.LazyLoad) List(java.util.List) Application(android.app.Application) TestEnvironmentLifecyclePlugin(org.robolectric.pluginapi.TestEnvironmentLifecyclePlugin) FixMethodOrder(org.junit.FixMethodOrder) Implementation(org.robolectric.annotation.Config.Implementation) Mockito.mock(org.mockito.Mockito.mock) TestEnvironmentSpec(org.robolectric.internal.AndroidSandbox.TestEnvironmentSpec) RobolectricTestRunner.defaultInjector(org.robolectric.RobolectricTestRunner.defaultInjector) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) HashMap(java.util.HashMap) FileSystemProvider(java.nio.file.spi.FileSystemProvider) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) JarEntry(java.util.jar.JarEntry) SuppressLint(android.annotation.SuppressLint) ResourcesMode(org.robolectric.internal.ResourcesMode) ResModeStrategy(org.robolectric.RobolectricTestRunner.ResModeStrategy) AndroidManifest(org.robolectric.manifest.AndroidManifest) Named(javax.inject.Named) Build(android.os.Build) DefaultSdkPicker(org.robolectric.plugins.DefaultSdkPicker) JarOutputStream(java.util.jar.JarOutputStream) Nonnull(javax.annotation.Nonnull) Before(org.junit.Before) AssumptionViolatedException(org.junit.AssumptionViolatedException) FrameworkMethod(org.junit.runners.model.FrameworkMethod) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) LazyApplication(org.robolectric.annotation.experimental.LazyApplication) SdkProvider(org.robolectric.pluginapi.SdkProvider) TempDirectory(org.robolectric.util.TempDirectory) TestUtil(org.robolectric.util.TestUtil) Metric(org.robolectric.pluginapi.perf.Metric) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) RunNotifier(org.junit.runner.notification.RunNotifier) PerfStatsReporter(org.robolectric.pluginapi.perf.PerfStatsReporter) ArrayList(java.util.ArrayList) Metric(org.robolectric.pluginapi.perf.Metric) Test(org.junit.Test)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Application (android.app.Application)1 Build (android.os.Build)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 FileOutputStream (java.io.FileOutputStream)1 Method (java.lang.reflect.Method)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 FileSystemProvider (java.nio.file.spi.FileSystemProvider)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 JarEntry (java.util.jar.JarEntry)1 JarOutputStream (java.util.jar.JarOutputStream)1 Collectors.toSet (java.util.stream.Collectors.toSet)1