Hi Matt,
I would write unit tests specific to your classes and then write
integration tests that exercise your code within Geode. Below is a simple
example of an integration test using Geode Cache. You should be able to
change that to use a Client Cache.
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.rules.TestName;
import java.io.Serializable;
import java.util.Properties;
/**
* Simple integration test with Geode.
*/
public class SimpleGeodeIntegrationTest {
private Cache cache;
private RegionFactory regionFactory;
@Rule
public TestName testName = new TestName();
@Rule
public RestoreSystemProperties restoreSystemProperties = new
RestoreSystemProperties();
@Before
public void setUp() throws Exception {
Properties geodeProperties = new Properties();
geodeProperties.put("name", testName.getMethodName());
geodeProperties.put("locators", "");
geodeProperties.put("mcast-port", "0");
this.cache = new CacheFactory(geodeProperties).create();
this.regionFactory = this.cache.createRegionFactory();
}
@After
public void tearDown() {
this.cache.close();
}
@Test
public void shouldDoX() {
Region<String, Serializable> myRegion =
this.regionFactory.<String, Serializable>create("MyRegion");
assertThat(myRegion, is(not(nullValue())));
}
}
-Kirk
On Thu, Mar 3, 2016 at 7:06 AM, Matt Ross <[email protected]> wrote:
> Hi all
>
> A colleague and I have been talking about the best strategies to do unit
> testing and TDD in Gemfire/Geode. Obviously writing unit tests for a
> Gemfire/Geode Client is fairly straightforward, but how would I unit test a
> function that I'm running on the cluster. Or how would I write tests for a
> cache listener? I've been pointed in the direction of power mock but could
> still use some more input from the community on what some of the better
> strategies are.
>
> Are there any examples on Github of how to write these serverside unit
> tests? Like I said at this point we're only able to do integration testing
> and unit testing of the client so I've been fairly limited in being able to
> do TDD. Thanks!
>
> --
> *Matthew Ross | Data Engineer | Pivotal*
> *625 Avenue of the Americas NY, NY 10011*
> *516-941-7535 <516-941-7535> | [email protected] <[email protected]> *
>
>