summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-03-29 23:13:30 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-03-29 23:13:30 +0000
commit9c285cb3f91063a8f14a43d48b11ecd8fba1c325 (patch)
tree6fc4259242e9b72c8e22e03b934d0e0d6af1ae58
parent801e16addd4504d90abacca493fb0bd0ac85908f (diff)
parente620638ebab821069907acf654de452ac4156e6d (diff)
downloadplatform_testing-9c285cb3f91063a8f14a43d48b11ecd8fba1c325.tar.gz
Call setUp() and cleanUp() on metric collectors in TestMetricRule. am: 343aa09c63 am: e620638eba
Original change: https://googleplex-android-review.googlesource.com/c/platform/platform_testing/+/17484052 Change-Id: Ibdb25417d3cf4a3dc6b8786a1858c07512ea46d4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--libraries/health/rules/src/android/platform/test/rule/TestMetricRule.java7
-rw-r--r--libraries/health/rules/tests/src/android/platform/test/rule/TestMetricRuleTest.java26
2 files changed, 28 insertions, 5 deletions
diff --git a/libraries/health/rules/src/android/platform/test/rule/TestMetricRule.java b/libraries/health/rules/src/android/platform/test/rule/TestMetricRule.java
index 398972833..e27389fd3 100644
--- a/libraries/health/rules/src/android/platform/test/rule/TestMetricRule.java
+++ b/libraries/health/rules/src/android/platform/test/rule/TestMetricRule.java
@@ -112,13 +112,15 @@ public class TestMetricRule extends TestWatcher {
// Initialize each listener.
for (BaseMetricListener listener : mMetricListeners) {
listener.setInstrumentation(InstrumentationRegistry.getInstrumentation());
- listener.setupAdditionalArgs();
}
}
@Override
protected void starting(Description description) {
for (BaseMetricListener listener : mMetricListeners) {
+ listener.setUp();
+ }
+ for (BaseMetricListener listener : mMetricListeners) {
try {
listener.testStarted(description);
} catch (Exception e) {
@@ -146,6 +148,9 @@ public class TestMetricRule extends TestWatcher {
e);
}
}
+ for (BaseMetricListener listener : mMetricListeners) {
+ listener.cleanUp();
+ }
}
@Override
diff --git a/libraries/health/rules/tests/src/android/platform/test/rule/TestMetricRuleTest.java b/libraries/health/rules/tests/src/android/platform/test/rule/TestMetricRuleTest.java
index b8ebe1c79..4f16e922f 100644
--- a/libraries/health/rules/tests/src/android/platform/test/rule/TestMetricRuleTest.java
+++ b/libraries/health/rules/tests/src/android/platform/test/rule/TestMetricRuleTest.java
@@ -80,9 +80,11 @@ public class TestMetricRuleTest {
.containsExactly(
"TestableCollector1#setInstrumentation",
"TestableCollector1#setupAdditionalArgs",
+ "TestableCollector1#onSetUp",
String.format("Test %s: TestableCollector1#onTestStart", DESCRIPTION),
"Test execution",
- String.format("Test %s: TestableCollector1#onTestEnd", DESCRIPTION))
+ String.format("Test %s: TestableCollector1#onTestEnd", DESCRIPTION),
+ "TestableCollector1#onCleanUp")
.inOrder();
}
@@ -98,6 +100,7 @@ public class TestMetricRuleTest {
.containsExactly(
"TestableCollector1#setInstrumentation",
"TestableCollector1#setupAdditionalArgs",
+ "TestableCollector1#onSetUp",
String.format("Test %s: TestableCollector1#onTestStart", DESCRIPTION),
"Test execution",
String.format(
@@ -105,7 +108,8 @@ public class TestMetricRuleTest {
DESCRIPTION,
new Failure(
DESCRIPTION, new RuntimeException(TEST_FAILURE_MESSAGE))),
- String.format("Test %s: TestableCollector1#onTestEnd", DESCRIPTION))
+ String.format("Test %s: TestableCollector1#onTestEnd", DESCRIPTION),
+ "TestableCollector1#onCleanUp")
.inOrder();
}
@@ -121,9 +125,11 @@ public class TestMetricRuleTest {
assertThat(sLogs)
.containsExactly(
"TestableCollector1#setInstrumentation",
- "TestableCollector1#setupAdditionalArgs",
"TestableCollector2#setInstrumentation",
+ "TestableCollector1#setupAdditionalArgs",
+ "TestableCollector1#onSetUp",
"TestableCollector2#setupAdditionalArgs",
+ "TestableCollector2#onSetUp",
String.format("Test %s: TestableCollector1#onTestStart", DESCRIPTION),
String.format("Test %s: TestableCollector2#onTestStart", DESCRIPTION),
"Test execution",
@@ -134,7 +140,9 @@ public class TestMetricRuleTest {
"Test %s: TestableCollector2#onTestFail with failure %s",
DESCRIPTION, failure),
String.format("Test %s: TestableCollector1#onTestEnd", DESCRIPTION),
- String.format("Test %s: TestableCollector2#onTestEnd", DESCRIPTION))
+ String.format("Test %s: TestableCollector2#onTestEnd", DESCRIPTION),
+ "TestableCollector1#onCleanUp",
+ "TestableCollector2#onCleanUp")
.inOrder();
}
@@ -187,6 +195,16 @@ public class TestMetricRuleTest {
}
@Override
+ public void onSetUp() {
+ sLogs.add(String.format("%s#%s", mName, "onSetUp"));
+ }
+
+ @Override
+ public void onCleanUp() {
+ sLogs.add(String.format("%s#%s", mName, "onCleanUp"));
+ }
+
+ @Override
public void onTestStart(DataRecord testData, Description description) {
sLogs.add(String.format("Test %s: %s#%s", description, mName, "onTestStart"));
}