├── .gitignore ├── .travis.yml ├── Gopkg.lock ├── Gopkg.toml ├── LICENSE ├── README.adoc ├── calc ├── calc.go ├── calc_ginkgo_test.go ├── calc_goblin_test.go ├── calc_gocheck_test.go ├── calc_goconvey_test.go ├── calc_gopwt_test.go ├── calc_gotestdeep_test.go ├── calc_standard_test.go └── calc_testify_test.go └── test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | vendor 3 | .idea 4 | coverage.txt 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.10.x 5 | 6 | install: 7 | - wget https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -O /tmp/dep 8 | - chmod +x /tmp/dep 9 | - /tmp/dep ensure 10 | 11 | script: 12 | - sh test.sh 13 | 14 | after_success: 15 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/ToQoz/gopwt" 6 | packages = [ 7 | ".", 8 | "assert", 9 | "translatedassert", 10 | "translator", 11 | "translator/internal" 12 | ] 13 | revision = "d7eb4bf2baf4ccca5d9e73f2289f3322d2eba917" 14 | version = "v2.0.0" 15 | 16 | [[projects]] 17 | name = "github.com/davecgh/go-spew" 18 | packages = ["spew"] 19 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 20 | version = "v1.1.0" 21 | 22 | [[projects]] 23 | name = "github.com/franela/goblin" 24 | packages = ["."] 25 | revision = "cd5d08fb4ede9eaac1812fdb513552e7404eae2e" 26 | version = "0.0.2" 27 | 28 | [[projects]] 29 | name = "github.com/go-check/check" 30 | packages = ["."] 31 | revision = "20d25e2804050c1cd24a7eea1e7a6447dd0e74ec" 32 | 33 | [[projects]] 34 | branch = "master" 35 | name = "github.com/gopherjs/gopherjs" 36 | packages = ["js"] 37 | revision = "8dffc02ea1cb8398bb73f30424697c60fcf8d4c5" 38 | 39 | [[projects]] 40 | name = "github.com/jtolds/gls" 41 | packages = ["."] 42 | revision = "77f18212c9c7edc9bd6a33d383a7b545ce62f064" 43 | version = "v4.2.1" 44 | 45 | [[projects]] 46 | name = "github.com/k0kubun/pp" 47 | packages = ["."] 48 | revision = "027a6d1765d673d337e687394dbe780dd64e2a1e" 49 | version = "v2.3.0" 50 | 51 | [[projects]] 52 | name = "github.com/mattn/go-colorable" 53 | packages = ["."] 54 | revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" 55 | version = "v0.0.9" 56 | 57 | [[projects]] 58 | name = "github.com/mattn/go-isatty" 59 | packages = ["."] 60 | revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" 61 | version = "v0.0.3" 62 | 63 | [[projects]] 64 | name = "github.com/mattn/go-runewidth" 65 | packages = ["."] 66 | revision = "9e777a8366cce605130a531d2cd6363d07ad7317" 67 | version = "v0.0.2" 68 | 69 | [[projects]] 70 | name = "github.com/maxatome/go-testdeep" 71 | packages = [ 72 | ".", 73 | "internal/ctxerr", 74 | "internal/dark", 75 | "internal/location", 76 | "internal/types", 77 | "internal/util" 78 | ] 79 | revision = "92fe9af33672b5d7a1cf668f09f84450f7347da0" 80 | version = "v1.0.7" 81 | 82 | [[projects]] 83 | name = "github.com/onsi/ginkgo" 84 | packages = [ 85 | ".", 86 | "config", 87 | "internal/codelocation", 88 | "internal/containernode", 89 | "internal/failer", 90 | "internal/leafnodes", 91 | "internal/remote", 92 | "internal/spec", 93 | "internal/spec_iterator", 94 | "internal/specrunner", 95 | "internal/suite", 96 | "internal/testingtproxy", 97 | "internal/writer", 98 | "reporters", 99 | "reporters/stenographer", 100 | "reporters/stenographer/support/go-colorable", 101 | "reporters/stenographer/support/go-isatty", 102 | "types" 103 | ] 104 | revision = "fa5fabab2a1bfbd924faf4c067d07ae414e2aedf" 105 | version = "v1.5.0" 106 | 107 | [[projects]] 108 | name = "github.com/onsi/gomega" 109 | packages = [ 110 | ".", 111 | "format", 112 | "internal/assertion", 113 | "internal/asyncassertion", 114 | "internal/oraclematcher", 115 | "internal/testingtsupport", 116 | "matchers", 117 | "matchers/support/goraph/bipartitegraph", 118 | "matchers/support/goraph/edge", 119 | "matchers/support/goraph/node", 120 | "matchers/support/goraph/util", 121 | "types" 122 | ] 123 | revision = "62bff4df71bdbc266561a0caee19f0594b17c240" 124 | version = "v1.4.0" 125 | 126 | [[projects]] 127 | name = "github.com/pmezard/go-difflib" 128 | packages = ["difflib"] 129 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 130 | version = "v1.0.0" 131 | 132 | [[projects]] 133 | name = "github.com/sergi/go-diff" 134 | packages = ["diffmatchpatch"] 135 | revision = "1744e2970ca51c86172c8190fadad617561ed6e7" 136 | version = "v1.0.0" 137 | 138 | [[projects]] 139 | name = "github.com/smartystreets/assertions" 140 | packages = [ 141 | ".", 142 | "internal/go-render/render", 143 | "internal/oglematchers" 144 | ] 145 | revision = "7678a5452ebea5b7090a6b163f844c133f523da2" 146 | version = "1.8.3" 147 | 148 | [[projects]] 149 | name = "github.com/smartystreets/goconvey" 150 | packages = [ 151 | "convey", 152 | "convey/gotest", 153 | "convey/reporting" 154 | ] 155 | revision = "9e8dc3f972df6c8fcc0375ef492c24d0bb204857" 156 | version = "1.6.3" 157 | 158 | [[projects]] 159 | name = "github.com/stretchr/testify" 160 | packages = ["assert"] 161 | revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" 162 | version = "v1.2.1" 163 | 164 | [[projects]] 165 | branch = "master" 166 | name = "golang.org/x/net" 167 | packages = [ 168 | "html", 169 | "html/atom", 170 | "html/charset" 171 | ] 172 | revision = "1e491301e022f8f977054da4c2d852decd59571f" 173 | 174 | [[projects]] 175 | branch = "master" 176 | name = "golang.org/x/sys" 177 | packages = ["unix"] 178 | revision = "bc2ef10f1b658ea907736406814a6187b49ea3ec" 179 | 180 | [[projects]] 181 | name = "golang.org/x/text" 182 | packages = [ 183 | "encoding", 184 | "encoding/charmap", 185 | "encoding/htmlindex", 186 | "encoding/internal", 187 | "encoding/internal/identifier", 188 | "encoding/japanese", 189 | "encoding/korean", 190 | "encoding/simplifiedchinese", 191 | "encoding/traditionalchinese", 192 | "encoding/unicode", 193 | "internal/gen", 194 | "internal/tag", 195 | "internal/utf8internal", 196 | "language", 197 | "runes", 198 | "transform", 199 | "unicode/cldr" 200 | ] 201 | revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" 202 | version = "v0.3.0" 203 | 204 | [[projects]] 205 | name = "gopkg.in/yaml.v2" 206 | packages = ["."] 207 | revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" 208 | version = "v2.2.1" 209 | 210 | [solve-meta] 211 | analyzer-name = "dep" 212 | analyzer-version = 1 213 | inputs-digest = "0b76847b8b3ce592adbdcc002fc749c35101224e8ac8625ffb3dd805f47aea7d" 214 | solver-name = "gps-cdcl" 215 | solver-version = 1 216 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | [[constraint]] 2 | name = "github.com/stretchr/testify" 3 | version = "1.2.1" 4 | 5 | [[constraint]] 6 | name = "github.com/go-check/check" 7 | revision = "20d25e2804050c1cd24a7eea1e7a6447dd0e74ec" 8 | 9 | [[constraint]] 10 | name = "github.com/onsi/ginkgo" 11 | version = "v1.5.0" 12 | 13 | [[constraint]] 14 | name = "github.com/onsi/gomega" 15 | version = "v1.4.0" 16 | 17 | [[constraint]] 18 | name = "github.com/franela/goblin" 19 | version = "v0.0.2" 20 | 21 | [[constraint]] 22 | name = "github.com/smartystreets/goconvey" 23 | version = "1.6.3" 24 | 25 | [[constraint]] 26 | name = "github.com/ToQoz/gopwt" 27 | version = "v2.0.0" 28 | 29 | [[constraint]] 30 | name = "github.com/maxatome/go-testdeep" 31 | version = "v1.0.7" 32 | 33 | [prune] 34 | go-tests = true 35 | unused-packages = true -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Go testing frameworks image:https://travis-ci.org/bmuschko/go-testing-frameworks.svg?branch=master["Build Status", link="https://travis-ci.org/bmuschko/go-testing-frameworks"] image:https://goreportcard.com/badge/github.com/bmuschko/go-testing-frameworks["Go Report Card", link="https://goreportcard.com/report/github.com/bmuschko/go-testing-frameworks"] image:https://codecov.io/gh/bmuschko/go-testing-frameworks/branch/master/graph/badge.svg["Codecov", link="https://codecov.io/gh/bmuschko/go-testing-frameworks"] 2 | 3 | Demonstrates the use of different testing frameworks for Go code. 4 | 5 | [options="header"] 6 | |======= 7 | |Go File |Framework |Description 8 | |`calc_standard_test.go` |https://golang.org/pkg/testing/[testing package] |Go standard library testing support 9 | |`calc_testify_test.go` |https://github.com/stretchr/testify[Testify] |Assertion and mock helpers 10 | |`calc_gocheck_test.go` |https://labix.org/gocheck[gocheck] |Assertion helpers 11 | |`calc_gopwt_test.go` |https://github.com/ToQoz/gopwt[gopwt] |Power assertion helpers 12 | |`calc_gotestdeep_test.go` |https://github.com/maxatome/go-testdeep[go-testdeep] |Deep comparison helpers 13 | |`calc_ginkgo_test.go` |https://github.com/onsi/ginkgo[Ginkgo] |Heavyweight BDD testing framework + assertion helpers 14 | |`calc_goblin_test.go` |https://github.com/franela/goblin[Goblin] |A Mocha like BDD testing framework 15 | |`calc_goconvey_test.go` |https://github.com/smartystreets/goconvey[GoConvey] |BDD testing framework with web UI 16 | |======= 17 | 18 | -------------------------------------------------------------------------------- /calc/calc.go: -------------------------------------------------------------------------------- 1 | package calc 2 | 3 | // Add two numbers. 4 | // Return the result. 5 | func Add(a, b int) int { 6 | return a + b 7 | } 8 | 9 | // Subtract two numbers. 10 | // Return the result. 11 | func Subtract(a, b int) int { 12 | return a - b 13 | } 14 | 15 | // Multiply two numbers. 16 | // Return the result. 17 | func Multiply(a, b int) int { 18 | return a * b 19 | } 20 | 21 | // Divide two numbers. 22 | // Return the result. 23 | func Divide(a, b int) float64 { 24 | return float64(a / b) 25 | } 26 | -------------------------------------------------------------------------------- /calc/calc_ginkgo_test.go: -------------------------------------------------------------------------------- 1 | package calc_test 2 | 3 | import ( 4 | . "github.com/bmuschko/go-testing-frameworks/calc" 5 | . "github.com/onsi/ginkgo" 6 | . "github.com/onsi/gomega" 7 | "testing" 8 | ) 9 | 10 | func TestCalc(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Calculator Suite") 13 | } 14 | 15 | var _ = Describe("Calculator", func() { 16 | Describe("Add numbers", func() { 17 | Context("1 and 2", func() { 18 | It("should be 3", func() { 19 | Expect(Add(1, 2)).To(Equal(3)) 20 | }) 21 | }) 22 | }) 23 | 24 | Describe("Subtract numbers", func() { 25 | Context("3 from 5", func() { 26 | It("should be 2", func() { 27 | Expect(Subtract(5, 3)).To(Equal(2)) 28 | }) 29 | }) 30 | }) 31 | 32 | Describe("Multiply numbers", func() { 33 | Context("5 with 6", func() { 34 | It("should be 30", func() { 35 | Expect(Multiply(5, 6)).To(Equal(30)) 36 | }) 37 | }) 38 | }) 39 | 40 | Describe("Divide numbers", func() { 41 | Context("10 by 2", func() { 42 | It("should be 30", func() { 43 | Expect(Divide(10, 2)).To(Equal(float64(5))) 44 | }) 45 | }) 46 | }) 47 | }) 48 | -------------------------------------------------------------------------------- /calc/calc_goblin_test.go: -------------------------------------------------------------------------------- 1 | package calc_test 2 | 3 | import ( 4 | . "github.com/bmuschko/go-testing-frameworks/calc" 5 | . "github.com/franela/goblin" 6 | "testing" 7 | ) 8 | 9 | func TestCalculator(t *testing.T) { 10 | g := Goblin(t) 11 | g.Describe("Calculator", func() { 12 | g.It("should add two numbers ", func() { 13 | g.Assert(Add(1, 2)).Equal(3) 14 | }) 15 | 16 | g.It("should subtract two numbers", func() { 17 | g.Assert(Subtract(5, 3)).Equal(2) 18 | }) 19 | 20 | g.It("should multiply two numbers", func() { 21 | g.Assert(Multiply(5, 6)).Equal(30) 22 | }) 23 | 24 | g.It("should divide two numbers", func() { 25 | g.Assert(Divide(10, 2)).Equal(float64(5)) 26 | }) 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /calc/calc_gocheck_test.go: -------------------------------------------------------------------------------- 1 | package calc_test 2 | 3 | import ( 4 | . "github.com/bmuschko/go-testing-frameworks/calc" 5 | . "github.com/go-check/check" 6 | "testing" 7 | ) 8 | 9 | func Test(t *testing.T) { 10 | TestingT(t) 11 | } 12 | 13 | type MySuite struct{} 14 | 15 | var _ = Suite(&MySuite{}) 16 | 17 | func (s *MySuite) TestAddWithGocheck(c *C) { 18 | result := Add(1, 2) 19 | c.Assert(result, Equals, 3) 20 | } 21 | 22 | func (s *MySuite) TestSubtractWithGocheck(c *C) { 23 | result := Subtract(5, 3) 24 | c.Assert(result, Equals, 2) 25 | } 26 | 27 | func (s *MySuite) TestMultiplyWithGocheck(c *C) { 28 | result := Multiply(5, 6) 29 | c.Assert(result, Equals, 30) 30 | } 31 | 32 | func (s *MySuite) TestDivideWithGocheck(c *C) { 33 | result := Divide(10, 2) 34 | c.Assert(result, Equals, float64(5)) 35 | } 36 | -------------------------------------------------------------------------------- /calc/calc_goconvey_test.go: -------------------------------------------------------------------------------- 1 | package calc_test 2 | 3 | import ( 4 | . "github.com/bmuschko/go-testing-frameworks/calc" 5 | . "github.com/smartystreets/goconvey/convey" 6 | "testing" 7 | ) 8 | 9 | func TestAddWithGoConvey(t *testing.T) { 10 | Convey("Adding two numbers", t, func() { 11 | x := 1 12 | y := 2 13 | 14 | Convey("should produce the expected result", func() { 15 | So(Add(x, y), ShouldEqual, 3) 16 | }) 17 | }) 18 | } 19 | 20 | func TestSubtractWithGoConvey(t *testing.T) { 21 | Convey("Subtracting two numbers", t, func() { 22 | x := 5 23 | y := 3 24 | 25 | Convey("should produce the expected result", func() { 26 | So(Subtract(x, y), ShouldEqual, 2) 27 | }) 28 | }) 29 | } 30 | 31 | func TestMultiplyWithGoConvey(t *testing.T) { 32 | Convey("Multiplying two numbers", t, func() { 33 | x := 5 34 | y := 6 35 | 36 | Convey("should produce the expected result", func() { 37 | So(Multiply(x, y), ShouldEqual, 30) 38 | }) 39 | }) 40 | } 41 | 42 | func TestDivideWithGoConvey(t *testing.T) { 43 | Convey("Dividing two numbers", t, func() { 44 | x := 10 45 | y := 2 46 | 47 | Convey("should produce the expected result", func() { 48 | So(Divide(x, y), ShouldEqual, float64(5)) 49 | }) 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /calc/calc_gopwt_test.go: -------------------------------------------------------------------------------- 1 | package calc_test 2 | 3 | import ( 4 | . "github.com/bmuschko/go-testing-frameworks/calc" 5 | . "github.com/ToQoz/gopwt/assert" 6 | . "github.com/ToQoz/gopwt" 7 | "testing" 8 | "flag" 9 | "os" 10 | ) 11 | 12 | func TestMain(m *testing.M) { 13 | flag.Parse() 14 | Empower() 15 | os.Exit(m.Run()) 16 | } 17 | 18 | func TestAddWithGopwt(t *testing.T) { 19 | result := Add(1, 2) 20 | OK(t, 3 == result) 21 | } 22 | 23 | func TestSubtractWithGopwt(t *testing.T) { 24 | result := Subtract(5, 3) 25 | OK(t, 2 == result) 26 | } 27 | 28 | func TestMultiplyWithGopwt(t *testing.T) { 29 | result := Multiply(5, 6) 30 | OK(t, 30 == result) 31 | } 32 | 33 | func TestDivideWithGopwt(t *testing.T) { 34 | result := Divide(10, 2) 35 | OK(t, float64(5) == result) 36 | } -------------------------------------------------------------------------------- /calc/calc_gotestdeep_test.go: -------------------------------------------------------------------------------- 1 | package calc_test 2 | 3 | import ( 4 | . "github.com/bmuschko/go-testing-frameworks/calc" 5 | . "github.com/maxatome/go-testdeep" 6 | "testing" 7 | ) 8 | 9 | func TestAddWithGoTestDeep(t *testing.T) { 10 | result := Add(1, 2) 11 | CmpNotZero(t, result) 12 | CmpDeeply(t, &result, Ptr(3)) 13 | CmpDeeply(t, result, Code(func (r int) (bool, string) { 14 | if r == 3 { 15 | return true, "" 16 | } 17 | return false, "Result should be 3" 18 | })) 19 | } 20 | 21 | func TestSubtractWithGoTestDeep(t *testing.T) { 22 | result := Subtract(5, 3) 23 | CmpNotZero(t, result) 24 | CmpDeeply(t, &result, Ptr(2)) 25 | CmpDeeply(t, result, Code(func (r int) (bool, string) { 26 | if r == 2 { 27 | return true, "" 28 | } 29 | return false, "Result should be 2" 30 | })) 31 | } 32 | 33 | func TestMultiplyWithGoTestDeep(t *testing.T) { 34 | result := Multiply(5, 6) 35 | CmpNotZero(t, result) 36 | CmpDeeply(t, &result, Ptr(30)) 37 | CmpDeeply(t, result, Code(func (r int) (bool, string) { 38 | if r == 30 { 39 | return true, "" 40 | } 41 | return false, "Result should be 30" 42 | })) 43 | } 44 | 45 | func TestDivideWithGoTestDeep(t *testing.T) { 46 | result := Divide(10, 2) 47 | CmpNotZero(t, result) 48 | CmpDeeply(t, &result, Ptr(float64(5))) 49 | CmpDeeply(t, result, Code(func (r float64) (bool, string) { 50 | if r == float64(5) { 51 | return true, "" 52 | } 53 | return false, "Result should be 5" 54 | })) 55 | } 56 | 57 | -------------------------------------------------------------------------------- /calc/calc_standard_test.go: -------------------------------------------------------------------------------- 1 | package calc_test 2 | 3 | import ( 4 | . "github.com/bmuschko/go-testing-frameworks/calc" 5 | "testing" 6 | ) 7 | 8 | func TestAddWithTestingPackage(t *testing.T) { 9 | result := Add(1, 2) 10 | 11 | if result != 3 { 12 | t.Errorf("Result was incorrect, got: %d, want: %d.", result, 3) 13 | } 14 | } 15 | 16 | func TestSubtractWithTestingPackage(t *testing.T) { 17 | result := Subtract(5, 3) 18 | 19 | if result != 2 { 20 | t.Errorf("Result was incorrect, got: %d, want: %d.", result, 2) 21 | } 22 | } 23 | 24 | func TestMultiplyWithTestingPackage(t *testing.T) { 25 | result := Multiply(5, 6) 26 | 27 | if result != 30 { 28 | t.Errorf("Result was incorrect, got: %d, want: %d.", result, 30) 29 | } 30 | } 31 | 32 | func TestDivideWithTestingPackage(t *testing.T) { 33 | result := Divide(10, 2) 34 | 35 | if result != 5 { 36 | t.Errorf("Result was incorrect, got: %f, want: %f.", result, float64(5)) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /calc/calc_testify_test.go: -------------------------------------------------------------------------------- 1 | package calc_test 2 | 3 | import ( 4 | . "github.com/bmuschko/go-testing-frameworks/calc" 5 | . "github.com/stretchr/testify/assert" 6 | "testing" 7 | ) 8 | 9 | func TestAddWithTestify(t *testing.T) { 10 | result := Add(1, 2) 11 | Equal(t, 3, result) 12 | } 13 | 14 | func TestSubtractWithTestify(t *testing.T) { 15 | result := Subtract(5, 3) 16 | Equal(t, 2, result) 17 | } 18 | 19 | func TestMultiplyWithTestify(t *testing.T) { 20 | result := Multiply(5, 6) 21 | Equal(t, 30, result) 22 | } 23 | 24 | func TestDivideWithTestify(t *testing.T) { 25 | result := Divide(10, 2) 26 | Equal(t, float64(5), result) 27 | } 28 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | echo "" > coverage.txt 5 | 6 | for d in $(go list ./... | grep -v vendor); do 7 | go test -race -coverprofile=profile.out -covermode=atomic $d 8 | if [ -f profile.out ]; then 9 | cat profile.out >> coverage.txt 10 | rm profile.out 11 | fi 12 | done --------------------------------------------------------------------------------