douqiao1983 2014-05-17 19:31
浏览 49
已采纳

前往:如何对多个软件包运行测试?

I have multiple packages under a subdirectory under src/, running the tests for each package with go test is working fine.

When trying to run all tests with go test ./... the tests are running but it fails..

the tests are running against local database servers, each test file has global variables with db pointers.

I tried to run the tests with -parallel 1 to prevent contention in the db, but the tests still fail.

what can be the issue here?

EDIT: some tests are failing on missing DB entries, I completely clear the DB before and after each test. the only reason I can think of why this is happening is because of some contention between tests.

EDIT 2:

each one of my test files has 2 global variables (using mgo):

var session *mgo.Session
var db *mgo.Database

also it has the following setup and teardown functions:

func setUp() {
   s, err := cfg.GetDBSession()
   if err != nil {
       panic(err)
   }

   session = s

   db = cfg.GetDB(session)

   db.DropDatabase()
}

func tearDown() {
   db.DropDatabase()

   session.Close()
}

each tests startup with setUp() and defer tearDown()

also cfg is:

package cfg

import (
    "labix.org/v2/mgo"
)

func GetDBSession() (*mgo.Session, error) {
    session, err := mgo.Dial("localhost")

    return session, err
}

func GetDB(session *mgo.Session) *mgo.Database {
    return session.DB("test_db")
}

EDIT 3:

I changed cfg to use a random database, the tests passed. it seems that the tests from multiple packages are running somewhat in parallel.

is it possible to force go test to run everything sequentially across packages ?

  • 写回答

4条回答 默认 最新

  • dongzenglin8292 2014-05-24 08:13
    关注

    apparently running go test -p 1 runs everything sequentially (including build), I haven't see this argument in go help test or go help testflag

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计