# 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)

*** ** * ** ***


```
@UnstableApi
public 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 `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION()`).

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

## Summary

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/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 methods |
|---|---|
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#assertOutput(android.content.Context,androidx.media3.test.utils.Dumper.Dumpable,java.lang.String)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/androidx/media3/test/utils/Dumper.Dumpable actual, https://developer.android.com/reference/java/lang/String.html dumpFile)` Asserts that the dump output of `actual` is equal to the contents of `dumpFile` in the `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DEFAULT_TEST_ASSET_DIRECTORY()`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#assertOutput(android.content.Context,java.lang.String,java.lang.String)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html actual, https://developer.android.com/reference/java/lang/String.html dumpFile)` Asserts that `actual` is equal to the contents of `dumpFile` in the `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DEFAULT_TEST_ASSET_DIRECTORY()`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#assertOutput(android.content.Context,androidx.media3.test.utils.Dumper.Dumpable,java.lang.String,java.lang.String)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/androidx/media3/test/utils/Dumper.Dumpable actual, https://developer.android.com/reference/java/lang/String.html assetDirectory, https://developer.android.com/reference/java/lang/String.html dumpFile )` Asserts that the dump output of `actual` is equal to the contents of `dumpFile` in the `assetDirectory`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#assertOutput(android.content.Context,java.lang.String,java.lang.String,java.lang.String)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html actual, https://developer.android.com/reference/java/lang/String.html assetDirectory, https://developer.android.com/reference/java/lang/String.html dumpFile )` Asserts that `actual` is equal to the contents of `dumpFile` in ` assetDirectory`. |

## Constants

### DEFAULT_TEST_ASSET_DIRECTORY

```
public static final String DEFAULT_TEST_ASSET_DIRECTORY = "../test_data/src/test/assets"
```

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

## Public methods

### assertOutput

```
public static void assertOutput(Context context, Dumper.Dumpable actual, String dumpFile)
```

Asserts that the dump output of `actual` is equal to the contents of `dumpFile` in the `https://developer.android.com/reference/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 `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION()` to `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL()` for local tests and to `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A context. |
| `https://developer.android.com/reference/androidx/media3/test/utils/Dumper.Dumpable actual` | The actual data. |
| `https://developer.android.com/reference/java/lang/String.html dumpFile` | The file path of the dump file in the assets directory. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### assertOutput

```
public static void assertOutput(Context context, String actual, String dumpFile)
```

Asserts that `actual` is equal to the contents of `dumpFile` in the `https://developer.android.com/reference/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 `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION()` to `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL()` for local tests and to `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A context. |
| `https://developer.android.com/reference/java/lang/String.html actual` | The actual data. |
| `https://developer.android.com/reference/java/lang/String.html dumpFile` | The file path of the dump file in the assets directory. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### assertOutput

```
public static void assertOutput(
    Context context,
    Dumper.Dumpable actual,
    String assetDirectory,
    String dumpFile
)
```

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 `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION()` to `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL()` for local tests and to `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A context. |
| `https://developer.android.com/reference/androidx/media3/test/utils/Dumper.Dumpable actual` | The actual data. |
| `https://developer.android.com/reference/java/lang/String.html assetDirectory` | The directory of the assets relative to the project working directory. Only used when `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION()` is set to `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL()`. |
| `https://developer.android.com/reference/java/lang/String.html dumpFile` | The file path of the dump file in the assets directory. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### assertOutput

```
public static void assertOutput(
    Context context,
    String actual,
    String assetDirectory,
    String dumpFile
)
```

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 `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION()` to `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL()` for local tests and to `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A context. |
| `https://developer.android.com/reference/java/lang/String.html actual` | The actual data. |
| `https://developer.android.com/reference/java/lang/String.html assetDirectory` | The directory of the assets relative to the project working directory. Only used when `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#DUMP_FILE_ACTION()` is set to `https://developer.android.com/reference/androidx/media3/test/utils/DumpFileAsserts#WRITE_TO_LOCAL()`. |
| `https://developer.android.com/reference/java/lang/String.html dumpFile` | The file path of the dump file in the assets directory. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |