Google has an in-memory emulator that you can use (most of the basic functions are implemented).
You need com.google.cloud:google-cloud-nio in your test path ( :0.25.0-alpha currently). Then you can use / implement the Storage interface implemented in the LocalStorageHelper test helper LocalStorageHelper .
Usage example:
import com.google.cloud.storage.Storage; import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper; @Test public void exampleInMemoryGoogleStorageTest() { Storage storage = LocalStorageHelper.getOptions().getService(); final String blobPath = "test/path/foo.txt"; final String testBucketName = "test-bucket"; BlobInfo blobInfo = BlobInfo.newBuilder( BlobId.of(testBucketName, blobPath) ).build(); storage.create(blobInfo, "randomContent".getBytes(StandardCharsets.UTF_8)); Iterable<Blob> allBlobsIter = storage.list(testBucketName).getValues();
source share