public static synchronized InternalCache createCache() {
    if (cache == null) {
      Properties dsp = new Properties();
      dsp.setProperty(MCAST_PORT, "0");
      dsp.setProperty(LOCATORS, "");
      DistributedSystem sys = DistributedSystem.connect(dsp);
      try {
        cache = (InternalCache) CacheFactory.create(sys);
      } catch (CacheExistsException exp) {
        cache = (InternalCache) CacheFactory.getInstance(sys);
      } catch (RegionExistsException rex) {
        cache = (InternalCache) CacheFactory.getInstance(sys);
      }
    }
    return cache;
  }
This method creates cache. The cache created is a loner, so this is only suitable for single VM
tests.
geode-junit/src/main/java/org/apache/geode/internal/cache/PartitionedRegionTestHelper.java