@@ -127,27 +127,90 @@ mvn test
127
127
Integration tests are also written using Junit4. They coexist with the unit tests in the ` src/test `
128
128
subdirectory. Integration tests follow the naming convention ` *IT.java ` (e.g. ` DataTestIT.java ` ),
129
129
which enables the Maven Surefire and Failsafe plugins to differentiate between the two types of
130
- tests. Integration tests are executed against a real life Firebase project, and therefore
131
- requires an Internet connection.
132
-
133
- Create a new project in the [ Firebase console] ( https://console.firebase.google.com/ ) if you do
134
- not already have one. Use a separate, dedicated project for integration tests since the test suite
135
- makes a large number of writes to the Firebase realtime database. Download the service account
136
- private key from the "Settings > Service Accounts" page of the project, and save it as
137
- ` integration_cert.json ` at the root of the codebase. Grant your service account the `Firebase
138
- Authentication Admin` role at
139
- [ Google Cloud Platform Console / IAM & admin] ( https://console.cloud.google.com/iam-admin ) . This is
140
- required to ensure that exported user records contain the password hashes of the user accounts.
141
- Also obtain the web API key of the project from the "Settings > General" page, and save it as
142
- ` integration_apikey.txt ` at the root of the codebase.
143
-
144
- Some of the integration tests require an
145
- [ Identity Platform] ( https://cloud.google.com/identity-platform/ ) project with multi-tenancy
146
- [ enabled] ( https://cloud.google.com/identity-platform/docs/multi-tenancy-quickstart#enabling_multi-tenancy ) .
147
- An existing Firebase project can be upgraded to an Identity Platform project without losing any
148
- functionality via the
149
- [ Identity Platform Marketplace Page] ( https://console.cloud.google.com/customer-identity ) . Note that
150
- charges may be incurred for active users beyond the Identity Platform free tier.
130
+ tests.
131
+
132
+ Integration tests are executed against a real life Firebase project. If you do not already
133
+ have one suitable for running the tests against, you can create a new project in the
134
+ [ Firebase Console] ( https://console.firebase.google.com ) following the setup guide below.
135
+ If you already have a Firebase project, you'll need to obtain credentials to communicate and
136
+ authorize access to your Firebase project:
137
+
138
+ 1 . Service account certificate: This allows access to your Firebase project through a service account
139
+ which is required for all integration tests. This can be downloaded as a JSON file from the
140
+ ** Settings > Service Accounts** tab of the Firebase console when you click the
141
+ ** Generate new private key** button. Copy the file into the repo so it's available at
142
+ ` integration_cert.json ` .
143
+ > ** Note:** Service accounts should be carefully managed and their keys should never be stored in publicly accessible source code or repositories.
144
+
145
+
146
+ 2 . Web API key: This allows for Auth sign-in needed for some Authentication and Tenant Management
147
+ integration tests. This is displayed in the ** Settings > General** tab of the Firebase console
148
+ after enabling Authentication as described in the steps below. Copy it and save to a new text
149
+ file at ` integration_apikey.txt ` .
150
+
151
+
152
+ Set up your Firebase project as follows:
153
+
154
+
155
+ 1 . Enable Authentication:
156
+ 1 . Go to the Firebase Console, and select ** Authentication** from the ** Build** menu.
157
+ 2 . Click on ** Get Started** .
158
+ 3 . Select ** Sign-in method > Add new provider > Email/Password** then enable both the
159
+ ** Email/Password** and ** Email link (passwordless sign-in)** options.
160
+
161
+
162
+ 2 . Enable Firestore:
163
+ 1 . Go to the Firebase Console, and select ** Firestore Database** from the ** Build** menu.
164
+ 2 . Click on the ** Create database** button. You can choose to set up Firestore either in
165
+ the production mode or in the test mode.
166
+
167
+
168
+ 3 . Enable Realtime Database:
169
+ 1 . Go to the Firebase Console, and select ** Realtime Database** from the ** Build** menu.
170
+ 2 . Click on the ** Create Database** button. You can choose to set up the Realtime Database
171
+ either in the locked mode or in the test mode.
172
+
173
+ > ** Note:** Integration tests are not run against the default Realtime Database reference and are
174
+ instead run against a database created at ` https://{PROJECT_ID}.firebaseio.com ` .
175
+ This second Realtime Database reference is created in the following steps.
176
+
177
+ 3 . In the ** Data** tab click on the kebab menu (3 dots) and select ** Create Database** .
178
+ 4 . Enter your Project ID (Found in the ** General** tab in ** Account Settings** ) as the
179
+ ** Realtime Database reference** . Again, you can choose to set up the Realtime Database
180
+ either in the locked mode or in the test mode.
181
+
182
+
183
+ 4 . Enable Storage:
184
+ 1 . Go to the Firebase Console, and select ** Storage** from the ** Build** menu.
185
+ 2 . Click on the ** Get started** button. You can choose to set up Cloud Storage
186
+ either in the production mode or in the test mode.
187
+
188
+
189
+ 5 . Enable the IAM API:
190
+ 1 . Go to the [ Google Cloud console] ( https://console.cloud.google.com )
191
+ and make sure your Firebase project is selected.
192
+ 2 . Select ** APIs & Services** from the main menu, and click the
193
+ ** ENABLE APIS AND SERVICES** button.
194
+ 3 . Search for and enable ** Identity and Access Management (IAM) API** by Google Enterprise API.
195
+
196
+
197
+ 6 . Enable Tenant Management:
198
+ 1 . Go to
199
+ [ Google Cloud console | Identity Platform] ( https://console.cloud.google.com/customer-identity/ )
200
+ and if it is not already enabled, click ** Enable** .
201
+ 2 . Then
202
+ [ enable multi-tenancy] ( https://cloud.google.com/identity-platform/docs/multi-tenancy-quickstart#enabling_multi-tenancy )
203
+ for your project.
204
+
205
+
206
+ 7 . Ensure your service account has the ** Firebase Authentication Admin** role. This is required
207
+ to ensure that exported user records contain the password hashes of the user accounts:
208
+ 1 . Go to [ Google Cloud console | IAM & admin] ( https://console.cloud.google.com/iam-admin ) .
209
+ 2 . Find your service account in the list. If not added click the pencil icon to edit its
210
+ permissions.
211
+ 3 . Click ** ADD ANOTHER ROLE** and choose ** Firebase Authentication Admin** .
212
+ 4 . Click ** SAVE** .
213
+
151
214
152
215
Now run the following command to invoke the integration test suite:
153
216
0 commit comments