Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/draganm/go-simplebdd
https://github.com/draganm/go-simplebdd
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/draganm/go-simplebdd
- Owner: draganm
- License: mit
- Created: 2020-12-28T22:10:22.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-28T23:08:49.000Z (about 4 years ago)
- Last Synced: 2023-03-27T13:43:36.561Z (almost 2 years ago)
- Language: Go
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simple BDD for Golang
This library is a simple syntactic sugar that utilizes existing Golang testing framework and add BDD style syntax on top of it.
# Motivation
I've been missing something that will keep me close to the Golang tests, but at the same time enable me to write BDD style Given/When/Then tests.
There are heavy weight approaches to this such as [Ginkgo](https://github.com/onsi/ginkgo) and I've been using it for years, but then I've realized that my tests are anything but readable for people who are not used to RSpec style of tests.# Why not just using Golang Sub-Tests
I've been writing tests of the form```golang
func TestAdd(t *testing.T) {var result int
t.Run("When I add 2 and 3", func(t *testing.T) {
result = 2 + 3
})t.Run("Then the result should be positive", func(t *testing.T) {
if result < 0 {
t.Fatal("not positive")
}
})t.Run("And the result should be 5", func(t *testing.T) {
if result != 5 {
t.Fatal("not equal 5")
}
})}
```and it works nicely, but if for some reason the step `Then the result should be positive` fails, the step `And the result should be 5` will still be executed, which is ugly to say the least and might cost you time waiting for the steps to time out.