Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products.

Go 1.16 is now generally available.

Package (v2.0.2)

Stay organized with collections Save and categorize content based on your preferences.

Package aetest provides an API for running dev_appserver for use in tests.

An example test file:

package foo_test

import (


func TestFoo(t *testing.T) {
    ctx, done, err := aetest.NewContext()
    if err != nil {
    defer done()

    it := &memcache.Item{
        Key:   "some-key",
        Value: []byte("some-value"),
    err = memcache.Set(ctx, it)
    if err != nil {
        t.Fatalf("Set err: %v", err)
    it, err = memcache.Get(ctx, "some-key")
    if err != nil {
        t.Fatalf("Get err: %v; want no error", err)
    if g, w := string(it.Value), "some-value" ; g != w {
        t.Errorf("retrieved Item.Value = %q, want %q", g, w)

The environment variable APPENGINE_DEV_APPSERVER specifies the location of the executable to use. If unset, the system PATH is consulted.



var PrepareDevAppserver func() error

PrepareDevAppserver is a hook which, if set, will be called before the is started, each time it is started. If aetest.NewContext is invoked from the goapp test tool, this hook is unnecessary.


func Login

func Login(u *user.User, req *http.Request)

Login causes the provided Request to act as though issued by the given user.

func Logout

func Logout(req *http.Request)

Logout causes the provided Request to act as though issued by a logged-out user.

func NewContext

func NewContext() (context.Context, func(), error)

NewContext starts an instance of the development API server, and returns a context that will route all API calls to that server, as well as a closure that must be called when the Context is no longer required.


type Instance interface {
	// Close kills the child process, releasing its resources.
	// NewRequest returns an *http.Request associated with this instance.
	NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)

Instance represents a running instance of the development API Server.

func NewInstance

func NewInstance(opts *Options) (Instance, error)

NewInstance launches a running instance of which can be used for multiple test Contexts that delegate all App Engine API calls to that instance. If opts is nil the default values are used.


type Options struct {
	// AppID specifies the App ID to use during tests.
	// By default, "testapp".
	AppID string
	// StronglyConsistentDatastore is whether the local datastore should be
	// strongly consistent. This will diverge from production behaviour.
	StronglyConsistentDatastore bool
	// SupportDatastoreEmulator is whether use Cloud Datastore Emulator or
	// use old SQLite based Datastore backend or use default settings.
	SupportDatastoreEmulator *bool
	// SuppressDevAppServerLog is whether the dev_appserver running in tests
	// should output logs.
	SuppressDevAppServerLog bool
	// StartupTimeout is a duration to wait for instance startup.
	// By default, 15 seconds.
	StartupTimeout time.Duration

Options is used to specify options when creating an Instance.