The environment variable APPENGINE_DEV_APPSERVER specifies the location of the
dev_appserver.py executable to use. If unset, the system PATH is consulted.
PrepareDevAppserver is a hook which, if set, will be called before the
dev_appserver.py is started, each time it is started. If aetest.NewContext
is invoked from the goapp test tool, this hook is unnecessary.
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.
Instance
typeInstanceinterface{// Close kills the child api_server.py process, releasing its resources.io.Closer// NewRequest returns an *http.Request associated with this instance.NewRequest(method,urlStrstring,bodyio.Reader)(*http.Request,error)}
Instance represents a running instance of the development API Server.
NewInstance launches a running instance of api_server.py 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.
Options
typeOptionsstruct{// AppID specifies the App ID to use during tests.// By default, "testapp".AppIDstring// StronglyConsistentDatastore is whether the local datastore should be// strongly consistent. This will diverge from production behaviour.StronglyConsistentDatastorebool// 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.SuppressDevAppServerLogbool// StartupTimeout is a duration to wait for instance startup.// By default, 15 seconds.StartupTimeouttime.Duration}
Options is used to specify options when creating an Instance.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003ePackage \u003ccode\u003eaetest\u003c/code\u003e provides an API for running the \u003ccode\u003edev_appserver\u003c/code\u003e to facilitate testing, as demonstrated in the provided example.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eNewContext\u003c/code\u003e starts a development API server instance, returning a context for API calls and a closure for cleanup.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAPPENGINE_DEV_APPSERVER\u003c/code\u003e environment variable specifies the path to the \u003ccode\u003edev_appserver.py\u003c/code\u003e executable; if unset, the system PATH is used.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eInstance\u003c/code\u003e interface represents a running development API server, offering methods to create requests and to close the instance, with \u003ccode\u003eNewInstance\u003c/code\u003e managing creation.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eOptions\u003c/code\u003e struct allows customization of the development server instance, including App ID, datastore consistency, logging, and startup timeout.\u003c/p\u003e\n"]]],[],null,["# Package google.golang.org/appengine/v2/aetest (v2.0.6)\n\n**Note:** To get more information about this package, such as access to older versions, view [this package on pkg.go.dev](https://pkg.go.dev/google.golang.org/appengine/v2/aetest). \n\u003cbr /\u003e\n\nPackage aetest provides an API for running dev_appserver for use in tests.\n\nAn example test file: \n\n```go\npackage foo_test\n\nimport (\n \"testing\"\n\n \"google.golang.org/appengine/v2/memcache\"\n \"google.golang.org/appengine/v2/aetest\"\n)\n\nfunc TestFoo(t *testing.T) {\n ctx, done, err := aetest.NewContext()\n if err != nil {\n t.Fatal(err)\n }\n defer done()\n\n it := &memcache.Item{\n Key: \"some-key\",\n Value: []byte(\"some-value\"),\n }\n err = memcache.Set(ctx, it)\n if err != nil {\n t.Fatalf(\"Set err: %v\", err)\n }\n it, err = memcache.Get(ctx, \"some-key\")\n if err != nil {\n t.Fatalf(\"Get err: %v; want no error\", err)\n }\n if g, w := string(it.Value), \"some-value\" ; g != w {\n t.Errorf(\"retrieved Item.Value = %q, want %q\", g, w)\n }\n}\n```\n\n\u003cbr /\u003e\n\nThe environment variable APPENGINE_DEV_APPSERVER specifies the location of the\ndev_appserver.py executable to use. If unset, the system PATH is consulted. \n\nVariables\n---------\n\n### PrepareDevAppserver\n\n var PrepareDevAppserver func() https://pkg.go.dev/builtin#error\n\nPrepareDevAppserver is a hook which, if set, will be called before the\ndev_appserver.py is started, each time it is started. If aetest.NewContext\nis invoked from the goapp test tool, this hook is unnecessary. \n\nFunctions\n---------\n\n### func Login\n\n func Login(u *https://pkg.go.dev/google.golang.org/appengine/v2/user.https://pkg.go.dev/google.golang.org/appengine/v2/user#User, req *https://pkg.go.dev/net/http.https://pkg.go.dev/net/http#Request)\n\nLogin causes the provided Request to act as though issued by the given user. \n\n### func Logout\n\n func Logout(req *https://pkg.go.dev/net/http.https://pkg.go.dev/net/http#Request)\n\nLogout causes the provided Request to act as though issued by a logged-out\nuser. \n\n### func NewContext\n\n func NewContext() (https://pkg.go.dev/context.https://pkg.go.dev/context#Context, func(), https://pkg.go.dev/builtin#error)\n\nNewContext starts an instance of the development API server, and returns\na context that will route all API calls to that server, as well as a\nclosure that must be called when the Context is no longer required. \n\nInstance\n--------\n\n type Instance interface {\n \t// Close kills the child api_server.py process, releasing its resources.\n \thttps://pkg.go.dev/io.https://pkg.go.dev/io#Closer\n \t// NewRequest returns an *http.Request associated with this instance.\n \tNewRequest(method, urlStr https://pkg.go.dev/builtin#string, body https://pkg.go.dev/io.https://pkg.go.dev/io#Reader) (*https://pkg.go.dev/net/http.https://pkg.go.dev/net/http#Request, https://pkg.go.dev/builtin#error)\n }\n\nInstance represents a running instance of the development API Server. \n\n### func NewInstance\n\n func NewInstance(opts *#google_golang_org_appengine_v2_aetest_Options) (#google_golang_org_appengine_v2_aetest_Instance, https://pkg.go.dev/builtin#error)\n\nNewInstance launches a running instance of api_server.py which can be used\nfor multiple test Contexts that delegate all App Engine API calls to that\ninstance.\nIf opts is nil the default values are used. \n\nOptions\n-------\n\n type Options struct {\n \t// AppID specifies the App ID to use during tests.\n \t// By default, \"testapp\".\n \tAppID https://pkg.go.dev/builtin#string\n \t// StronglyConsistentDatastore is whether the local datastore should be\n \t// strongly consistent. This will diverge from production behaviour.\n \tStronglyConsistentDatastore https://pkg.go.dev/builtin#bool\n \t// SupportDatastoreEmulator is whether use Cloud Datastore Emulator or\n \t// use old SQLite based Datastore backend or use default settings.\n \tSupportDatastoreEmulator *https://pkg.go.dev/builtin#bool\n \t// SuppressDevAppServerLog is whether the dev_appserver running in tests\n \t// should output logs.\n \tSuppressDevAppServerLog https://pkg.go.dev/builtin#bool\n \t// StartupTimeout is a duration to wait for instance startup.\n \t// By default, 15 seconds.\n \tStartupTimeout https://pkg.go.dev/time.https://pkg.go.dev/time#Duration\n }\n\nOptions is used to specify options when creating an Instance."]]