diff options
author | Teng-Hui Zhu <ztenghui@google.com> | 2016-10-11 14:10:36 -0700 |
---|---|---|
committer | Teng-Hui Zhu <ztenghui@google.com> | 2016-10-11 15:39:05 -0700 |
commit | 578f47149d9cc674fd5a0e7f7ce8453cb54d8979 (patch) | |
tree | 9e6eccdba4514ac6a7474b015d0467d3d478b908 | |
parent | 275f6bc8abff305325d1a052646b057248ae169d (diff) |
Switch APCT Perf test to JUnit 4.11 friendly
b/31928255
Test: run LayoutPerfTest VectorDrawablePerfTest before and after the change
data is consistent.
Change-Id: I30de1f09b1df571479009048d621fef57b94f316
-rw-r--r-- | apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java b/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java index 3933b57753dc..64b0bf589a1b 100644 --- a/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java +++ b/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java @@ -18,8 +18,9 @@ package android.perftests.utils; import android.support.test.InstrumentationRegistry; -import org.junit.rules.TestWatcher; +import org.junit.rules.TestRule; import org.junit.runner.Description; +import org.junit.runners.model.Statement; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; @@ -47,7 +48,7 @@ import static junit.framework.Assert.assertTrue; * name when using parameterization. */ -public class PerfStatusReporter extends TestWatcher { +public class PerfStatusReporter implements TestRule { private final BenchmarkState mState = new BenchmarkState(); public BenchmarkState getBenchmarkState() { @@ -55,33 +56,39 @@ public class PerfStatusReporter extends TestWatcher { } @Override - protected void succeeded(Description description) { - String invokeMethodName = description.getMethodName(); - // validate and simplify the function name. - // First, remove the "test" prefix which normally comes from CTS test. - // Then make sure the [subTestName] is valid, not just numbers like [0]. - if (invokeMethodName.startsWith("test")) { - assertTrue("The test name " + invokeMethodName + " is too short", - invokeMethodName.length() > 5); - invokeMethodName = invokeMethodName.substring(4, 5).toLowerCase() - + invokeMethodName.substring(5); - } + public Statement apply(Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + String invokeMethodName = description.getMethodName(); + // validate and simplify the function name. + // First, remove the "test" prefix which normally comes from CTS test. + // Then make sure the [subTestName] is valid, not just numbers like [0]. + if (invokeMethodName.startsWith("test")) { + assertTrue("The test name " + invokeMethodName + " is too short", + invokeMethodName.length() > 5); + invokeMethodName = invokeMethodName.substring(4, 5).toLowerCase() + + invokeMethodName.substring(5); + } - int index = invokeMethodName.lastIndexOf('['); - if (index > 0) { - boolean allDigits = true; - for (int i = index + 1; i < invokeMethodName.length() - 1; i++) { - if (!Character.isDigit(invokeMethodName.charAt(i))) { - allDigits = false; - break; + int index = invokeMethodName.lastIndexOf('['); + if (index > 0) { + boolean allDigits = true; + for (int i = index + 1; i < invokeMethodName.length() - 1; i++) { + if (!Character.isDigit(invokeMethodName.charAt(i))) { + allDigits = false; + break; + } + } + assertFalse("The name in [] can't contain only digits for " + invokeMethodName, + allDigits); } - } - assertFalse("The name in [] can't contain only digits for " + invokeMethodName, - allDigits); - } - mState.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(), - invokeMethodName); - } + base.evaluate(); + mState.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(), + invokeMethodName); + } + }; + } } |