You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gcloud-java provides tools to make testing your application easier.
4
+
5
+
### Testing interactions with Datastore
6
+
7
+
#### On your machine
8
+
9
+
You can test against a temporary local datastore by following these steps:
10
+
11
+
1. Start the local datastore emulator using `LocalGcdHelper`. This can be done in two ways:
12
+
- Run `LocalGcdHelper.java`'s `main` method with arguments `START` and (optionally) `--port=<port number>`. This will create a temporary folder on your computer and bind `localhost:<port number>` for communication with the local datastore. The port number is an optional argument. If no port number is specified, port 8080 will be used.
13
+
- Call `LocalGcdHelper.start(<project ID>, <port number>)` before running your tests. Save the `LocalGcdHelper` object returned so that you can stop the emulator later.
14
+
15
+
2. In your program, create and use a datastore whose host is set host to `localhost:<port number>`. For example,
- If you ran `LocalGcdHelper.java`'s `main` function to start the emulator, run `LocalGcdHelper.java`'s `main` method with arguments `STOP` and (optionally) `--port=<port number>`. If the port is not supplied, the program will attempt to close the last port started.
27
+
- If you ran `LocalGcdHelper.start()` to start the emulator, call the `stop()` method on the `LocalGcdHelper` object returned by `LocalGcdHelper.start()`.
28
+
29
+
#### On a remote machine
30
+
31
+
You can test against a remote datastore emulator as well. To do this, set the `DatastoreOptions` project endpoint to the hostname of the remote machine, like the example below.
.host("http://<hostname of machine>")
Note that the remote datastore must be running before your tests are run. Also note that the `host` argument must start with "http://" or "https://".
42
+
43
+
44
+
### Testing interactions with Storage
45
+
46
+
There currently isn't an emulator for Google Cloud Storage, so an alternative is to create a test project. `RemoteGcsHelper` contains convenience methods to make setting up and cleaning up the test project easier. To use this class, follow the steps below:
47
+
48
+
1. Create a test Google App Engine project.
49
+
50
+
2. Create and download a JSON key by going to the Google Developer's Console and clicking API's & Auth > Credentials > Add Credentials > Service Credentials. Choose "JSON", download the file, and note its location.
51
+
52
+
3. Set environment variables `GCLOUD_TESTS_PROJECT_ID` and `GCLOUD_TESTS_KEY_PATH` according to your test project's ID and the location of the newly-downloaded JSON key file.
53
+
54
+
4. Create and and use a `RemoteGcsHelper` object.
55
+
Here is an example that uses the RemoteGcsHelper to create a bucket and clear the bucket at the end of the test.
0 commit comments