testify

    3熱度

    2回答

    我已經爲我的結構(https://github.com/stretchr/testify#suite-package)設置了測試套件。在我能夠通過指定一種模式運行單個測試之前: go test -v ./services/gateways/... -run mytest 此方法在轉換後不起作用。運氣不好還是有辦法?

    2熱度

    1回答

    我有一個問題,在使用testify在golang中聲明一個聲明爲變量的函數。 在同一個包中聲明的測試和函數。 var testableFunction = func(abc string) string {...} 現在我有一個不同的文件與單元測試調用testableFunction func TestFunction(t *testing.T){ ... res:=tes

    0熱度

    1回答

    我正在使用testify測試XML編組並使用strings.Contains來檢查我希望包含在XML中的線是否實際存在。 但是,我想區分實際與期望的xml。 目前,我的代碼看起來是這樣的: func (suite *BookSuite) TestXMLMarshal() { priceXML, priceErr := xml.Marshal(PriceType{Price: 10, Ty

    3熱度

    2回答

    我使用testify來測試我的代碼,我想檢查一個函數是否被調用。 我做了以下內容: type Foo struct { mock.Mock } func (m Foo) Bar() { } func TestFoo(t *testing.T) { m := Foo{} m.Bar() m.AssertCalled(t, "Bar") }

    18熱度

    6回答

    這裏就是我想要做的事: main.go package main import ( "fmt" "net/http" "github.com/gorilla/mux" ) func main() { mainRouter := mux.NewRouter().StrictSlash(true) mainRouter.HandleFunc(

    1熱度

    1回答

    我進口看起來像下面這樣: import ( "testing" "github.com/stretchr/testify/assert" ) 當我嘗試嘗試運行「走出去測試」我得到錯誤信息: cannot find package "github.com/stretchr/testify/assert" in any of: /Users/[username]/go/src/github

    0熱度

    3回答

    我一直無法找到從golang包模擬方法的解決方案。 例如,我的項目的代碼嘗試在Os.Getwd()返回錯誤時進行恢復。我可以考慮對此進行單元測試的最簡單方法是模擬Os.Getwd()方法返回錯誤,並驗證代碼是否相應地工作。 我試過使用testify,但它似乎不可能。 任何人有任何經驗嗎?