Skip to content

ramesh-lingappan/gae-test-util-java

Repository files navigation

AppEngine Local Testing Helper

A small test utility library to help with appengine local unit testing.

Checkou the medium article AppEngine unit testing made easy with JUnit Rules

Setup

AppEngineRule class helps to configure the necessary appengine local test stubs for unit testing. You can able to quickly setup using the default configurations or provide custom configurations

@Rule 
pubilc final AppEngineRule appengineRule = AppEngineRule.builder()
             .withAll() // all will setup all the appengine services like Datastore, Queue, Memcache etc
            .build();


@Rule 
pubilc final AppEngineRule appengineRule = AppEngineRule.builder()
            .withTypes(Datastore, Memcache, Queue) //or configure using selective service 
            .build();  

// or go for complex one 
@Rule
public final AppEngineRule appEngineRule = AppEngineRule.builder()

        // datastore & generate auto indexes xml file 
        .withDatastore(datastoreConfig().setNoIndexAutoGen(false))

        // with memecache 
        .withMemcache()

        // queue with specific queue.xml file 
        .withQueue("{PROJECT_DIR}/src/main/webapp/WEB-INF/queue.xml")

        // UserService with an admin user loggedIn
        .withUserService(UserInfo.createAdmin("admin@testing.com", "admin_123"))

        // with url fetch service
        .withUrlFetcher()

        .build();

Installation

Checkout the releases for binaries Releases

Usage

Datastore Setup

public class DatastoreTest {

    @Rule
    public final AppEngineRule rule = AppEngineRule.builder()
            .withDatastore(datastoreConfig().setNoIndexAutoGen(false))
            .build();

    @Before
    public void setUp() {
        ofy().factory().register(TestEntity.class);
    }

    @Test
    public void testGet() {

        TestEntity testEntity = new TestEntity();
        ofy().save().entity(testEntity).now();

        System.out.println(testEntity);

        TestEntity entity = ofy().load().type(TestEntity.class).id(testEntity.getId()).now();
        assertNotNull(entity);
    }
}

About

Appengine Local Testing Helper

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages