use of org.robolectric.pluginapi.perf.Metric in project robolectric by robolectric.
the class PerfStatsCollectorTest method shouldRunAndMeasureExceptionThrowingCallable.
@Test
public void shouldRunAndMeasureExceptionThrowingCallable() throws Exception {
collector.measure("event", () -> {
fakeClock.delay(10);
return "return value";
});
try {
collector.measure("event", () -> {
fakeClock.delay(5);
throw new RuntimeException("fake");
});
fail("should have thrown");
} catch (RuntimeException e) {
assertThat(e.getMessage()).isEqualTo("fake");
}
Collection<Metric> metrics = collector.getMetrics();
assertThat(metrics).containsAtLeast(new Metric("event", 1, 10, true), new Metric("event", 1, 5, false));
}
use of org.robolectric.pluginapi.perf.Metric in project robolectric by robolectric.
the class PerfStatsCollectorTest method shouldMeasureElapsedTimeForEvents.
@Test
public void shouldMeasureElapsedTimeForEvents() throws Exception {
Event firstEvent = collector.startEvent("first event");
fakeClock.delay(20);
firstEvent.finished();
Collection<Metric> metrics = collector.getMetrics();
assertThat(metrics).containsExactly(new Metric("first event", 1, 20, true));
}
use of org.robolectric.pluginapi.perf.Metric in project robolectric by robolectric.
the class PerfStatsCollectorTest method shouldMeasureElapsedTimeForRepeatedEvents.
@Test
public void shouldMeasureElapsedTimeForRepeatedEvents() throws Exception {
Event firstEvent = collector.startEvent("repeatable event");
fakeClock.delay(20);
firstEvent.finished();
Event secondEvent = collector.startEvent("repeatable event");
fakeClock.delay(20);
secondEvent.finished();
Event thirdEvent = collector.startEvent("repeatable event");
fakeClock.delay(20);
thirdEvent.finished();
Collection<Metric> metrics = collector.getMetrics();
assertThat(metrics).containsExactly(new Metric("repeatable event", 3, 60, true));
}
use of org.robolectric.pluginapi.perf.Metric in project robolectric by robolectric.
the class SandboxTestRunner method reportPerfStats.
private void reportPerfStats(PerfStatsCollector perfStatsCollector) {
if (perfStatsReporters.isEmpty()) {
return;
}
Metadata metadata = perfStatsCollector.getMetadata();
Collection<Metric> metrics = perfStatsCollector.getMetrics();
for (PerfStatsReporter perfStatsReporter : perfStatsReporters) {
try {
perfStatsReporter.report(metadata, metrics);
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of org.robolectric.pluginapi.perf.Metric 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");
}
Aggregations