# DumpFileAsserts

# DumpFileAsserts

Artifact:[androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/DumpFileAsserts.java+class:androidx.media3.test.utils.DumpFileAsserts)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts "View this page in Java")

<br />

```
@UnstableApi
class DumpFileAsserts
```

<br />

*** ** * ** ***

Helper class to enable assertions based on golden-data dump files.

Allows the golden files to be easily updated with new data (see more info in the docs on[DUMP_FILE_ACTION](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION())).

Compatible with[Dumper.Dumpable](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/Dumper.Dumpable)but can also be used directly with Strings generated through different means.

## Summary

|                                        ### Constants                                         |
|----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | [DEFAULT_TEST_ASSET_DIRECTORY](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DEFAULT_TEST_ASSET_DIRECTORY())` = "../test_data/src/test/assets"` The default test asset directory used if no other directory is specified. |

|                                    ### Public functions                                     |
|---------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [assertOutput](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#assertOutput(android.content.Context,androidx.media3.test.utils.Dumper.Dumpable,java.lang.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!, actual: `[Dumper.Dumpable](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/Dumper.Dumpable)`!, dumpFile: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!)` Asserts that the dump output of`actual`is equal to the contents of`dumpFile`in the[DEFAULT_TEST_ASSET_DIRECTORY](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DEFAULT_TEST_ASSET_DIRECTORY()). |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [assertOutput](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#assertOutput(android.content.Context,java.lang.String,java.lang.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!, actual: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!, dumpFile: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!)` Asserts that`actual`is equal to the contents of`dumpFile`in the[DEFAULT_TEST_ASSET_DIRECTORY](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DEFAULT_TEST_ASSET_DIRECTORY()).                                                                         |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [assertOutput](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#assertOutput(android.content.Context,androidx.media3.test.utils.Dumper.Dumpable,java.lang.String,java.lang.String))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!,` ` actual: `[Dumper.Dumpable](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/Dumper.Dumpable)`!,` ` assetDirectory: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!,` ` dumpFile: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` `)` Asserts that the dump output of`actual`is equal to the contents of`dumpFile`in the`assetDirectory`.  |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [assertOutput](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#assertOutput(android.content.Context,java.lang.String,java.lang.String,java.lang.String))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!,` ` actual: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!,` ` assetDirectory: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!,` ` dumpFile: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` `)` Asserts that`actual`is equal to the contents of`dumpFile`in` assetDirectory`.                                                                             |

## Constants

### DEFAULT_TEST_ASSET_DIRECTORY

```
const val DEFAULT_TEST_ASSET_DIRECTORY = "../test_data/src/test/assets": String!
```

The default test asset directory used if no other directory is specified.  

## Public functions

### assertOutput

```
java-static fun assertOutput(context: Context!, actual: Dumper.Dumpable!, dumpFile: String!): Unit
```

Asserts that the dump output of`actual`is equal to the contents of`dumpFile`in the[DEFAULT_TEST_ASSET_DIRECTORY](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DEFAULT_TEST_ASSET_DIRECTORY()).

If the assertion fails because of an intended change in the output or a new dump file needs to be created, set[DUMP_FILE_ACTION](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION())to[WRITE_TO_LOCAL](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL())for local tests and to[WRITE_TO_DEVICE](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_DEVICE())for instrumentation tests, and run the test again. Instead of assertion,`actual`will be written to`dumpFile`. For instrumentation tests, this new dump file needs to be copied to the project asset folder manually.  

|                                                        Parameters                                                         |
|---------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`                             | A context.                                              |
| `actual: `[Dumper.Dumpable](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/Dumper.Dumpable)`!` | The actual data.                                        |
| `dumpFile: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                          | The file path of the dump file in the assets directory. |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### assertOutput

```
java-static fun assertOutput(context: Context!, actual: String!, dumpFile: String!): Unit
```

Asserts that`actual`is equal to the contents of`dumpFile`in the[DEFAULT_TEST_ASSET_DIRECTORY](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DEFAULT_TEST_ASSET_DIRECTORY()).

If the assertion fails because of an intended change in the output or a new dump file needs to be created, set[DUMP_FILE_ACTION](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION())to[WRITE_TO_LOCAL](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL())for local tests and to[WRITE_TO_DEVICE](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_DEVICE())for instrumentation tests, and run the test again. Instead of assertion,`actual`will be written to`dumpFile`. For instrumentation tests, this new dump file needs to be copied to the project asset folder manually.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`    | A context.                                              |
| `actual: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`   | The actual data.                                        |
| `dumpFile: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The file path of the dump file in the assets directory. |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### assertOutput

```
java-static fun assertOutput(
    context: Context!,
    actual: Dumper.Dumpable!,
    assetDirectory: String!,
    dumpFile: String!
): Unit
```

Asserts that the dump output of`actual`is equal to the contents of`dumpFile`in the`assetDirectory`.

If the assertion fails because of an intended change in the output or a new dump file needs to be created, set[DUMP_FILE_ACTION](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION())to[WRITE_TO_LOCAL](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL())for local tests and to[WRITE_TO_DEVICE](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_DEVICE())for instrumentation tests, and run the test again. Instead of assertion,`actual`will be written to`dumpFile`. For instrumentation tests, this new dump file needs to be copied to the project asset folder manually.  

|                                                        Parameters                                                         |
|---------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`                             | A context.                                                                                                                                                                                                                                                                                                                                                  |
| `actual: `[Dumper.Dumpable](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/Dumper.Dumpable)`!` | The actual data.                                                                                                                                                                                                                                                                                                                                            |
| `assetDirectory: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                    | The directory of the assets relative to the project working directory. Only used when[DUMP_FILE_ACTION](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION())is set to[WRITE_TO_LOCAL](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL()). |
| `dumpFile: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                          | The file path of the dump file in the assets directory.                                                                                                                                                                                                                                                                                                     |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### assertOutput

```
java-static fun assertOutput(
    context: Context!,
    actual: String!,
    assetDirectory: String!,
    dumpFile: String!
): Unit
```

Asserts that`actual`is equal to the contents of`dumpFile`in`
assetDirectory`.

If the assertion fails because of an intended change in the output or a new dump file needs to be created, set[DUMP_FILE_ACTION](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION())to[WRITE_TO_LOCAL](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL())for local tests and to[WRITE_TO_DEVICE](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_DEVICE())for instrumentation tests, and run the test again. Instead of assertion,`actual`will be written to`dumpFile`. For instrumentation tests, this new dump file needs to be copied to the project asset folder manually.  

|                                               Parameters                                               |
|--------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`          | A context.                                                                                                                                                                                                                                                                                                                                                  |
| `actual: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`         | The actual data.                                                                                                                                                                                                                                                                                                                                            |
| `assetDirectory: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The directory of the assets relative to the project working directory. Only used when[DUMP_FILE_ACTION](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION())is set to[WRITE_TO_LOCAL](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL()). |
| `dumpFile: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`       | The file path of the dump file in the assets directory.                                                                                                                                                                                                                                                                                                     |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |