|
1 | 1 | # Firestore Spec Tests
|
2 | 2 |
|
| 3 | +The Firestore Spec Tests are a suite of unit tests that fake out the external |
| 4 | +sources of events so that they can be completely controlled from the tests |
| 5 | +themselves and verify the correct handling of these events. |
3 | 6 |
|
| 7 | +There are three sources of external events in the SDK: user writes, input from |
| 8 | +the persistence layer, and input from the watch stream. The spec tests fake all |
| 9 | +of these. Since these external events are asynchronous in nature, in the real |
| 10 | +world there is some non-determinism in the ordering of events. The spec tests |
| 11 | +allow these orderings to be specified explicitly, enabling orderings that are |
| 12 | +difficult or impossible to force when connected to a real backend. |
| 13 | + |
| 14 | +The Firestore Spec Tests are portable and must be kept in sync between the Web |
| 15 | +SDK (this SDK), Android SDK, and iOS SDK. The Web SDK contains the authoritative |
| 16 | +test definitions and they must be manually "exported" to the Android SDK and iOS |
| 17 | +SDK when they change. |
| 18 | + |
| 19 | +## Running the Tests |
| 20 | + |
| 21 | +The spec tests are part of the unit test suite of each SDK. Therefore, to run |
| 22 | +the spec tests simply run the entire unit test suite and the spec tests will be |
| 23 | +executed as a part of it. |
| 24 | + |
| 25 | +For example, in the Web SDK (this SDK), the best way to run the spec tests is |
| 26 | +via the Intellij IDEA IDE. After following the instructions to set up IntelliJ |
| 27 | +in [CONTRIBUTING.md](../../../CONTRIBUTING.md), run the "Unit Tests" Run |
| 28 | +Configuration, which will include the spec tests. |
| 29 | + |
| 30 | +## Exporting the Tests |
| 31 | + |
| 32 | +To export the tests use the [generate_spec_json.sh](../generate_spec_json.sh) |
| 33 | +script, specifying a single argument whose value is the destination directory |
| 34 | +into which to place the generated files. |
| 35 | + |
| 36 | +#### Exporting the Tests to the Android SDK |
| 37 | + |
| 38 | +To export the spec tests to the Android SDK, run the following command: |
| 39 | + |
| 40 | +``` |
| 41 | +cd ~/firebase-js-sdk/packages/firestore/test/unit && |
| 42 | +./generate_spec_json.sh ~/firebase-android-sdk/firebase-firestore/src/test/resources/json |
| 43 | +``` |
| 44 | + |
| 45 | +This command assumes that this Git repository is cloned into `~/firebase-js-sdk` |
| 46 | +and the Android SDK is cloned into `~/firebase-android-sdk`. |
| 47 | + |
| 48 | +#### Exporting the Tests to the iOS SDK |
| 49 | + |
| 50 | +To export the spec tests to the iOS SDK, run the following command: |
| 51 | + |
| 52 | +``` |
| 53 | +cd ~/firebase-js-sdk/packages/firestore/test/unit && |
| 54 | +./generate_spec_json.sh ~/firebase-ios-sdk/Firestore/Example/Tests/SpecTests/json |
| 55 | +``` |
| 56 | + |
| 57 | +This command assumes that this Git repository is cloned into `~/firebase-js-sdk` |
| 58 | +and the iOS SDK is cloned into `~/firebase-ios-sdk`. |
0 commit comments