How to write tests for API based on Google Cloud Endpoints?

Is there some way to test API written using Google Cloud Endpoint using JUnit or other framework?

In documentation there is an example using curl commands and perhaps the logic behind this is to test API on client side only.

When I tried to find some approaches how to test API from server-side, I came across the possibility of writing JUnit tests and invoking HttpURLConnection's to localhost, but there are problems with this approach. For example, the instance of app engine should be already running before testing, but I deploy locally with maven and testing is prior deploying, so if I have broken tests it doesn't deploy dev server and I do not feel that that is the right way to rewrite maven steps.

Edit 1: Found something similar for Python: How to unit test Google Cloud Endpoints


With Objectify you can do it like this. For example, let's declare our BooksEndpoint as follows:

    name = "books",
    version = "v1",
    namespace = @ApiNamespace(ownerDomain = "", ownerName = "", packagePath = "")
public class BooksEndpoint {

    @ApiMethod(name = "saveBook")
    public void saveBook(Book book, User user) throws OAuthRequestException, IOException {
        if (user == null) {
            throw new OAuthRequestException("User is not authorized");

        Account account = AccountService.create().getAccount(user);

                .entity(BookRecord.fromBook(account, book))


To test it, you would need following dependencies:

testCompile ''
testCompile ''
testCompile ''
testCompile 'junit:junit:4.12'

Now, test will look as follows:

public class BooksEndpointTest {

    private final LocalServiceTestHelper testHelper = new LocalServiceTestHelper(
            new LocalDatastoreServiceTestConfig()

    private Closeable objectifyService;

    public void setUp() throws Exception {
        objectifyService = ObjectifyService.begin(); // required if you want to use Objectify

    public void tearDown() throws Exception {

    public void testSaveBook() throws Exception {
        // Create Endpoint and execute your method
        new BooksEndpoint().saveBook(
                Book.create("id", "name", "author"),
                new User("", "authDomain")

        // Check what was written into datastore
        BookRecord bookRecord = ofy().load().type(BookRecord.class).first().now();

        // Assert that it is correct (simplified)
        assertEquals("name", bookRecord.getName());


Note, I'm using BookRecord and Book here - those are my Entity and POJO, nothing special.

First, thanks for the link to the Python answer. Regarding Java, this Udacity course is based around a Google Cloud Endpoints project in Java, and it has many code examples on how to test endpoints. The source code is here. I have been trying to reproduce the project in Python, and I unfortunately cannot provide any details based on personal experience with testing endpoints written in Java, but I hope the links help!

Need Your Help

Arraylist random coordinates


i am new to java and i need to make an array list that stores random coordinates..anyone help? is this right what i am doing? i want to store alot of coordinates so that i can use them later on.....