pranavraja / zen Goto Github PK
View Code? Open in Web Editor NEWBDD testing framework for Go
License: Other
BDD testing framework for Go
License: Other
I submitted a tiny pull request lately to enable a test. The code below is completely different than that.
My main purpose of forking was to change the code to be more like Dan North's original BDD definitions in his original 2008 introduction of BDD. Aka, the "purist" vision of BDD with Given/When/Then
that follows the overall scenario:
Given some initial context (the givens),
When an event occurs,
then ensure some outcomes.
I also come from a .NET background where I was an avid user of Machine.Specifications (aka MSpec) BDD framework and his patterns. More specifically, his very nicely formatted TEXT and HTML outputs that was completely human readable.
Therefore, I present the following updates to Go's Zen BDD Framework: Full Contextual Scenarios
// bdd_test.go
//
func TestBddSceneriosUsingContextAndSpecifications(t *testing.T) {
Given(t, "a BDD scenario", func(when When) {
when("an event occurs", func(it It) {
it("should evaluate to 1", func(expect Expect) {
expect(1).ToEqual(1)
})
it("should also evaluate to 3", func(expect Expect) {
expect(3).ToEqual(3)
})
it("should perform another evaluation", func(expect Expect) {
expect(4).ToNotEqual(5)
})
it("should also perform another evaluation", func(expect Expect) {
expect("hellow").ToNotEqual("world")
})
})
// common context
count := 0
before := func() {
count++
}
after := func() {
count--
}
setup := Setup(before, after)
when("using Setup() in extended-style", func(it It) {
it("should increment count to 1", setup(func(expect Expect) {
expect(count).ToEqual(1)
}))
if count != 0 {
t.Error("In BDD-specs, count should have been reset to zero by the teardown func")
}
})
})
}
Which outputs the following:
Given a BDD scenario
When an event occurs
It should evaluate to 1
It should also evaluate to 3
It should perform another evaluation
It should also perform another evaluation
When using Setup() in extended-style
It should increment count to 1
PASS
ok github.com/eduncan911/zen 0.008s
Note my new tests that start at the "Given a BDD scenario". You will also notice that I inserted "Given / When / It" in the output.
If you are interested in a Pull request for these changes, let me know. You can have a look at the changes here:
In short:
It remains completely compatible with all existing Zen users. Just the output is formatted differently. If you run all tests, you will the output has been tweaked to group multiple existing it()
funcs:
eduncanmac1:~/go/src/github.com/eduncan911/zen [master +0 ~5 -0]$ go test
When Equality Specs
It should have an integer equal to itself
It should not have any integer equal to nil
When Setup Specs
It should execute before by incrementing count
Given a BDD scenario
When an event occurs
It should evaluate to 1
It should also evaluate to 3
It should perform another evaluation
It should also perform another evaluation
When using Setup() in extended-style
It should increment count to 1
PASS
ok github.com/eduncan911/zen 0.008s
That runs all existing tests before my changes indicating it remains backwards compatible; then, my new scenario specs are run along side them seamlessly.
Well, there is a breaking change: it is for anyone using custom formatters - I extended the interface to have two additional methods:
type formatter interface {
PrintContext()
PrintWhen()
PrintTitle()
PrintError(string)
}
You'll need to implement a PrintContext()
and PrintWhen()
. If anyone really has overwritten the default formatter, I'm sure this will be a welcome upgrade/tweak.
It's also missing documentation which I am happy to add later in another pull request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.