Commit 4c9780ab by tonihei Committed by Oliver Woodman

Add ABR unit tests

This parameterized test execute a single playback with a variety of
specified network conditions, user country and network types, and then
compares some basic ABR performance data against a dump file to detect
changes.

PiperOrigin-RevId: 356468304
parent 94a4b905
...@@ -40,6 +40,9 @@ import java.lang.annotation.RetentionPolicy; ...@@ -40,6 +40,9 @@ import java.lang.annotation.RetentionPolicy;
*/ */
public class DumpFileAsserts { public class DumpFileAsserts {
/** The default test asset directory used if no other directory is specified. */
public static final String DEFAULT_TEST_ASSET_DIRECTORY = "../../testdata/src/test/assets";
private static final String DUMP_UPDATE_INSTRUCTIONS = private static final String DUMP_UPDATE_INSTRUCTIONS =
"To update the dump file, change DumpFileAsserts#DUMP_FILE_ACTION to WRITE_TO_LOCAL (for" "To update the dump file, change DumpFileAsserts#DUMP_FILE_ACTION to WRITE_TO_LOCAL (for"
+ " Robolectric tests) or WRITE_TO_DEVICE (for instrumentation tests) and re-run the" + " Robolectric tests) or WRITE_TO_DEVICE (for instrumentation tests) and re-run the"
...@@ -68,22 +71,85 @@ public class DumpFileAsserts { ...@@ -68,22 +71,85 @@ public class DumpFileAsserts {
private DumpFileAsserts() {} private DumpFileAsserts() {}
/**
* Asserts that the dump output of {@code actual} is equal to the contents of {@code dumpFile} in
* the {@link #DEFAULT_TEST_ASSET_DIRECTORY}.
*
* <p>If the assertion fails because of an intended change in the output or a new dump file needs
* to be created, set {@link #DUMP_FILE_ACTION} to {@link #WRITE_TO_LOCAL} for local tests and to
* {@link #WRITE_TO_DEVICE} for instrumentation tests, and run the test again. Instead of
* assertion, {@code actual} will be written to {@code dumpFile}. For instrumentation tests, this
* new dump file needs to be copied to the project asset folder manually.
*
* @param context A context.
* @param actual The actual data.
* @param dumpFile The file path of the dump file in the assets directory.
*/
public static void assertOutput(Context context, Dumper.Dumpable actual, String dumpFile) public static void assertOutput(Context context, Dumper.Dumpable actual, String dumpFile)
throws IOException { throws IOException {
assertOutput(context, new Dumper().add(actual).toString(), dumpFile); assertOutput(
context, new Dumper().add(actual).toString(), DEFAULT_TEST_ASSET_DIRECTORY, dumpFile);
} }
/** /**
* Asserts that {@code actual} is equal to the contents of {@code dumpFile}. * Asserts that the dump output of {@code actual} is equal to the contents of {@code dumpFile} in
* the {@code assetDirectory}.
* *
* <p>If the assertion fails because of an intended change in the output or a new dump file needs * <p>If the assertion fails because of an intended change in the output or a new dump file needs
* to be created, set {@link #DUMP_FILE_ACTION} to {@link #WRITE_TO_LOCAL} for local tests and to * to be created, set {@link #DUMP_FILE_ACTION} to {@link #WRITE_TO_LOCAL} for local tests and to
* {@link #WRITE_TO_DEVICE} for instrumentation tests, and run the test again. Instead of * {@link #WRITE_TO_DEVICE} for instrumentation tests, and run the test again. Instead of
* assertion, {@code actual} will be written to {@code dumpFile}. For instrumentation tests, this * assertion, {@code actual} will be written to {@code dumpFile}. For instrumentation tests, this
* new dump file needs to be copied to the project {@code testdata/src/test} folder manually. * new dump file needs to be copied to the project asset folder manually.
*
* @param context A context.
* @param actual The actual data.
* @param assetDirectory The directory of the assets relative to the project working directory.
* Only used when {@link #DUMP_FILE_ACTION} is set to {@link #WRITE_TO_LOCAL}.
* @param dumpFile The file path of the dump file in the assets directory.
*/
public static void assertOutput(
Context context, Dumper.Dumpable actual, String assetDirectory, String dumpFile)
throws IOException {
assertOutput(context, new Dumper().add(actual).toString(), assetDirectory, dumpFile);
}
/**
* Asserts that {@code actual} is equal to the contents of {@code dumpFile} in the {@link
* #DEFAULT_TEST_ASSET_DIRECTORY}.
*
* <p>If the assertion fails because of an intended change in the output or a new dump file needs
* to be created, set {@link #DUMP_FILE_ACTION} to {@link #WRITE_TO_LOCAL} for local tests and to
* {@link #WRITE_TO_DEVICE} for instrumentation tests, and run the test again. Instead of
* assertion, {@code actual} will be written to {@code dumpFile}. For instrumentation tests, this
* new dump file needs to be copied to the project asset folder manually.
*
* @param context A context.
* @param actual The actual data.
* @param dumpFile The file path of the dump file in the assets directory.
*/ */
public static void assertOutput(Context context, String actual, String dumpFile) public static void assertOutput(Context context, String actual, String dumpFile)
throws IOException { throws IOException {
assertOutput(context, actual, DEFAULT_TEST_ASSET_DIRECTORY, dumpFile);
}
/**
* Asserts that {@code actual} is equal to the contents of {@code dumpFile} in {@code
* assetDirectory}.
*
* <p>If the assertion fails because of an intended change in the output or a new dump file needs
* to be created, set {@link #DUMP_FILE_ACTION} to {@link #WRITE_TO_LOCAL} for local tests and to
* {@link #WRITE_TO_DEVICE} for instrumentation tests, and run the test again. Instead of
* assertion, {@code actual} will be written to {@code dumpFile}. For instrumentation tests, this
* new dump file needs to be copied to the project asset folder manually.
*
* @param context A context.
* @param actual The actual data.
* @param assetDirectory The directory of the assets relative to the project working directory.
* Only used when {@link #DUMP_FILE_ACTION} is set to {@link #WRITE_TO_LOCAL}.
* @param dumpFile The file path of the dump file in the assets directory.
*/
public static void assertOutput(
Context context, String actual, String assetDirectory, String dumpFile) throws IOException {
if (DUMP_FILE_ACTION == COMPARE_WITH_EXISTING) { if (DUMP_FILE_ACTION == COMPARE_WITH_EXISTING) {
String expected; String expected;
try { try {
...@@ -98,7 +164,7 @@ public class DumpFileAsserts { ...@@ -98,7 +164,7 @@ public class DumpFileAsserts {
} else { } else {
File file = File file =
DUMP_FILE_ACTION == WRITE_TO_LOCAL DUMP_FILE_ACTION == WRITE_TO_LOCAL
? new File(StandardSystemProperty.USER_DIR.value(), "../../testdata/src/test/assets") ? new File(StandardSystemProperty.USER_DIR.value(), assetDirectory)
: context.getExternalFilesDir(null); : context.getExternalFilesDir(null);
file = new File(file, dumpFile); file = new File(file, dumpFile);
Assertions.checkStateNotNull(file.getParentFile()).mkdirs(); Assertions.checkStateNotNull(file.getParentFile()).mkdirs();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment