Unit testing with Google App Engine

google-app-engine
java

#1

Hi,
I have a problem with performing my Google App Engine unit tests.

Here is the test:

public class RecommendedCategoriesEntitiesTest {
 private final LocalServiceTestHelper helper =
            new LocalServiceTestHelper(
                    new LocalDatastoreServiceTestConfig()
                            .setDefaultHighRepJobPolicyUnappliedJobPercentage(0));

    private DatastoreService datastore;

    @Before
    public void setUp() {
        helper.setUp();
        datastore = DatastoreServiceFactory.getDatastoreService();
    }

    @After
    public void tearDown() {
        helper.tearDown();
    }

    @Test
    public void addAnEntity() throws Exception {

        Entity category = new Entity("RecommendedCategory");
        category.setProperty("name", "Tours");

        datastore.put(category);

        Entity got = datastore.get( category.getKey());

        assertEquals((String)got.getProperty("name"), "Tours");
    }
}

Here is how I am imported GAE for unit test in CircleCI:

- curl -o $HOME/google_appengine_1.9.28.zip https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.28.zip - unzip -q -d $HOME $HOME/google_appengine_1.9.28.zip

Here is the error I get when running the tests on CircleCI:

java.lang.NoSuchMethodError at RecommendedCategoriesEntitiesTest.java:48

It looks like the problem is with the GAE local unit test class DatastoreService and the method it is trying to call is datastore.put(…); I am initialising the DatastoreService class in the test class using:

@Before public void setUp() { helper.setUp(); datastore = DatastoreServiceFactory.getDatastoreService(); }

The strange thing is that it works OK on my machine. Is there anything obvious that I may be doing wrong?


#2