In theory, you should only test your own code. If you have to test your framework, you are using the wrong framework. Something remote like connection to and using a Google API is something you would only test in an integration test, but not a unit test.
So, in this case, I would try to encapsulate your own code in a way that allows you to put mock versions of the classes that connect the the Google API and do something there into it, for example by writing a GoogleAPIConnector Interface
or something like this:
public interface GoogleAPIConnector {
void connect();
String doSomeWork(String email);
}
You would create one "real" implementation of this interface, that actually connects to Google and does the real work. Testing this would be the scope of an integration test. Would probably look somehow like this...
public class GoogleAPIConnectorImpl {
private Directory directory;
@Override
public void connect() {
this.directory = DirectoryServiceFactory.getDirectoryService();
}
@Override
public String doSomeWork(String email){
return this.directory.groups().get(email).execute();
}
}
For unit tests, you would instead use mock object that returns "fake" data instead of the real deal, allowing you to run tests with the assumption that the google connection works, testing all the stuff you wrote around it, for example (with Mockito):
GoogleAPIConnector connector = mock(GoogleAPIConnector.class);
when(connector.doSomeWork("someone@example.com")).thenReturn("hello world");
SomeClass someClass = new SomeClass(""someone@example.com");
someClass.setConnector(connector);
String result = someClass.work();
assertThat(result, equalTo("hello world");
verify(connector, times(1)).doSomeWork("someone@example.com");
This way, your unit tests will be fast and not depend on the Google API (if your network is down, they will still succeed). Your integration tests are slower and depend on the Google API, but as they don't have to run as often (and don't have to fail the build), that's ok.