duanhe2027 2015-11-04 18:19
浏览 15
已采纳

App Engine本地单元测试不同的实例[GO]

I have an issue with testing separate methods, each test case is running on a different instance and address.

I'm looking for a way to set up the API address in order to preform the tests on the same API server.

I assuming that this warning is part of the issue.

WARNING  2015-11-04 18:15:25,003 devappserver2.py:779] DEFAULT_VERSION_HOSTNAME will not be set correctly with --port=0

This command will set the API server but I can't do the same for test...

dev_appserver.py .  --api_port 55555
  • 写回答

1条回答 默认 最新

  • douka19950505 2015-11-10 00:00
    关注

    Using aetest.NewInstance you can make sure that all your unit tests share a single instance:

    var inst aetest.Instance
    
    func TestMain(m *testing.M) {
       var err error
       inst, err = aetest.NewInstance(nil)
       if err != nil {
           log.Fatalf("aetest.NewInstance: %v", err)
       }
    
       e := m.Run()
       inst.Close()
       os.Exit(e)
    }
    
    func TestMyTest(t *testing.T) {
       req, err := inst.NewRequest("GET", "/foo/bar", nil)
       // etc.
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据