How to speed up unit tests of Google App Engine Go?

I am currently writing a lot of unit tests for my package, which runs on GAE Go. This package focuses on saving and loading data to and from the application / data warehouse. Thus, I have about 20 unit test files that look something like this:

package Data import ( "appengine" "appengine/aetest" . "gopkg.in/check.v1" "testing" ) func TestUsers(t *testing.T) { TestingT(t) } type UsersSuite struct{} var _ = Suite(&UsersSuite{}) const UserID string = "UserID" func (s *UsersSuite) TestSaveLoad(cc *C) { c, err := aetest.NewContext(nil) cc.Assert(err, IsNil) defer c.Close() ... 

As a result, each individual test file starts its own version of devappserver:

enter image description here

Repeat this 20 times and my unit tests last more than 10 minutes.

I am wondering how can I speed up my test suite? Should I have only one file that creates aetest.NewContext and passes it, or is it due to the fact that I use separate packages for each unit test? How can I speed this up?

+6
source share
1 answer

You can use the custom function TestMain :

 var ctx aetest.Context var c aetest.Context func TestMain(m *testing.M) { var err error ctx, err = aetest.NewContext(nil) if err != nil { panic(err) } code := m.Run() // this runs the tests ctx.Close() os.Exit(code) } func TestUsers(t *testing.T) { // use ctx here } 

Thus, the dev server starts once for all tests. More information about TestMain is available here: http://golang.org/pkg/testing/#hdr-Main .

+4
source

Source: https://habr.com/ru/post/983292/


All Articles