Google Cloud Shell has application default credentials from its compute instance which will allow you to run an integration test without having to obtain GOOGLE_APPLICATION_CREDENTIALS.
However, tests require an additional environment variable GOOGLE_CLOUD_PROJECT_NUMBER to run. For instance,
private static final String GOOGLE_CLOUD_PROJECT_NUMBER =
System.getenv("GOOGLE_CLOUD_PROJECT_NUMBER");Here, the program needs you to provide your Google Cloud Project Number in an environment variable.
To run a sample's integration test in Cloud Shell:
-
cd samples/- all samples are located injava-pubsublite/samples/snippetsdirectory. -
mvn clean -Dtest=QuickStartIT test- this runs the integration test forUpdateTopicExample.java.
To run a sample, update the developer's TODO section in the snippet, then:
-
cd samples/snippets/- all samples are located injava-pubsublite/samples/snippetsdirectory. -
mvn compile exec:java -Dexec.mainClass=pubsublite.ListTopicsExample- this should list the topics in your project.