Skip to content

Commit

Permalink
Add example for go-testdeep
Browse files Browse the repository at this point in the history
  • Loading branch information
bmuschko committed Dec 19, 2018
1 parent 91889a8 commit 701f503
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 9 deletions.
15 changes: 14 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Expand Up @@ -26,6 +26,10 @@
name = "github.com/ToQoz/gopwt"
version = "v2.0.0"

[[constraint]]
name = "github.com/maxatome/go-testdeep"
version = "v1.0.7"

[prune]
go-tests = true
unused-packages = true
17 changes: 9 additions & 8 deletions README.adoc
Expand Up @@ -4,13 +4,14 @@ Demonstrates the use of different testing frameworks for Go code.

[options="header"]
|=======
|Go File |Framework |Description
|`calc_standard_test.go` |https://golang.org/pkg/testing/[testing package] |Go standard library testing support
|`calc_testify_test.go` |https://github.com/stretchr/testify[Testify] |Assertion and mock helpers
|`calc_gocheck_test.go` |https://labix.org/gocheck[gocheck] |Assertion helpers
|`calc_gopwt_test.go` |https://github.com/ToQoz/gopwt[gopwt] |Power assertion helpers
|`calc_ginkgo_test.go` |https://github.com/onsi/ginkgo[Ginkgo] |Heavyweight BDD testing framework + assertion helpers
|`calc_goblin_test.go` |https://github.com/franela/goblin[Goblin] |A Mocha like BDD testing framework
|`calc_goconvey_test.go` |https://github.com/smartystreets/goconvey[GoConvey] |BDD testing framework with web UI
|Go File |Framework |Description
|`calc_standard_test.go` |https://golang.org/pkg/testing/[testing package] |Go standard library testing support
|`calc_testify_test.go` |https://github.com/stretchr/testify[Testify] |Assertion and mock helpers
|`calc_gocheck_test.go` |https://labix.org/gocheck[gocheck] |Assertion helpers
|`calc_gopwt_test.go` |https://github.com/ToQoz/gopwt[gopwt] |Power assertion helpers
|`calc_gotestdeep_test.go` |https://github.com/maxatome/go-testdeep[go-testdeep] |Deep comparison helpers
|`calc_ginkgo_test.go` |https://github.com/onsi/ginkgo[Ginkgo] |Heavyweight BDD testing framework + assertion helpers
|`calc_goblin_test.go` |https://github.com/franela/goblin[Goblin] |A Mocha like BDD testing framework
|`calc_goconvey_test.go` |https://github.com/smartystreets/goconvey[GoConvey] |BDD testing framework with web UI
|=======

56 changes: 56 additions & 0 deletions calc/calc_gotestdeep_test.go
@@ -0,0 +1,56 @@
package calc_test

import (
. "github.com/bmuschko/go-testing-frameworks/calc"
. "github.com/maxatome/go-testdeep"
"testing"
)

func TestAddWithGoTestDeep(t *testing.T) {
result := Add(1, 2)
CmpNotZero(t, result)
CmpDeeply(t, &result, Ptr(3))
CmpDeeply(t, result, Code(func (r int) (bool, string) {
if r == 3 {
return true, ""
}
return false, "Result should be 3"
}))
}

func TestSubtractWithGoTestDeep(t *testing.T) {
result := Subtract(5, 3)
CmpNotZero(t, result)
CmpDeeply(t, &result, Ptr(2))
CmpDeeply(t, result, Code(func (r int) (bool, string) {
if r == 2 {
return true, ""
}
return false, "Result should be 2"
}))
}

func TestMultiplyWithGoTestDeep(t *testing.T) {
result := Multiply(5, 6)
CmpNotZero(t, result)
CmpDeeply(t, &result, Ptr(30))
CmpDeeply(t, result, Code(func (r int) (bool, string) {
if r == 30 {
return true, ""
}
return false, "Result should be 30"
}))
}

func TestDivideWithGoTestDeep(t *testing.T) {
result := Divide(10, 2)
CmpNotZero(t, result)
CmpDeeply(t, &result, Ptr(float64(5)))
CmpDeeply(t, result, Code(func (r float64) (bool, string) {
if r == float64(5) {
return true, ""
}
return false, "Result should be 5"
}))
}

0 comments on commit 701f503

Please sign in to comment.