SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Downloaden Sie, um offline zu lesen
HI THERE!HI THERE!
I'M BARTŁOMIEJ KLIMCZAKI'M BARTŁOMIEJ KLIMCZAK
#gopher #GDE #blogger
WHAT IS BDD?WHAT IS BDD?
THERE'S A LIBRARY FOR IT!THERE'S A LIBRARY FOR IT!
https://github.com/DATA-DOG/godog
... AND THIS LIBRARY IS... AND THIS LIBRARY IS
AWESOME!AWESOME!
... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC
... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC
it runs as an external program
... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC
it runs as an external program
creates a temporary main_test file
... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC
it runs as an external program
creates a temporary main_test file
it parses the temporary program's output
... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC
it runs as an external program
creates a temporary main_test file
it parses the temporary program's output
displays the ouput in gherkin's format
THERE'RE WEAKNESSES OF THISTHERE'RE WEAKNESSES OF THIS
SOLUTIONSOLUTION
doesn't use the standard testing package
THERE'RE WEAKNESSES OF THISTHERE'RE WEAKNESSES OF THIS
SOLUTIONSOLUTION
doesn't use the standard testing package
no good code coverage
THERE'RE WEAKNESSES OF THISTHERE'RE WEAKNESSES OF THIS
SOLUTIONSOLUTION
doesn't use the standard testing package
no good code coverage
no debugging the test code!
THERE'RE WEAKNESSES OF THISTHERE'RE WEAKNESSES OF THIS
SOLUTIONSOLUTION
doesn't use the standard testing package
no good code coverage
no debugging the test code!
no built-in features like build tags
THE GLOBAL STATE!THE GLOBAL STATE!
// Godogs available to eat
var Godogs int
// somewhere in the test
func FeatureContext(s *godog.Suite) {
s.Step(`^there are (d+) godogs$`, thereAreGodogs)
s.Step(`^I eat (d+)$`, iEat)
s.Step(`^there should be (d+) remaining$`, thereShoul
s.BeforeScenario(func(interface{}) {
Godogs = 0 // clean the state before every sce
})
}
THAT'S WHYTHAT'S WHY EXISTSEXISTS
Main goals:
GOBDDGOBDD
https://github.com/go-bdd/gobdd
THAT'S WHYTHAT'S WHY EXISTSEXISTS
Main goals:
no magic
GOBDDGOBDD
https://github.com/go-bdd/gobdd
THAT'S WHYTHAT'S WHY EXISTSEXISTS
Main goals:
no magic
easy to use
GOBDDGOBDD
https://github.com/go-bdd/gobdd
KEY FEATURES:KEY FEATURES:
uses gherkin syntax
KEY FEATURES:KEY FEATURES:
uses gherkin syntax
uses standard testing package
KEY FEATURES:KEY FEATURES:
uses gherkin syntax
uses standard testing package
allows debugging and profiling the application
KEY FEATURES:KEY FEATURES:
uses gherkin syntax
uses standard testing package
allows debugging and profiling the application
uses context between steps
QUICK STARTQUICK START
go get github.com/go-bdd/gobdd
func TestScenarios(t *testing.T) {
suite := gobdd.NewSuite(t)
suite.AddStep(`I add (d+) and (d+)`, add)
suite.AddStep(`I the result should equal (d+)`, check
suite.Run()
}
# features/my.feature
Feature: math operations
Scenario: add two digits
When I add 1 and 2
Then I the result should equal 3
THE CONTEXTTHE CONTEXT
THE CONTEXTTHE CONTEXT
holds the data from previous steps
THE CONTEXTTHE CONTEXT
holds the data from previous steps
holds step's parameters fetched from the step’s
definition (may change)
THE CONTEXTTHE CONTEXT
holds the data from previous steps
holds step's parameters fetched from the step’s
definition (may change)
easier parallelism
THE CONTEXTTHE CONTEXT
holds the data from previous steps
holds step's parameters fetched from the step’s
definition (may change)
easier parallelism
The goal: hold every required information about the
step itself to be successfully executed.
THE CONTEXTTHE CONTEXT
Passing information between tests
// in the first step
ctx.Set(name{}, "John")
// in the second step
fmt.Printf("Hi %sn", ctx.GetString(name{})) // prints "Hi Joh
THE CONTEXTTHE CONTEXT
List of functions for getting the data
Context.GetInt(key interface{}, [defaultValue]) int
Context.GetFloat32(key interface{}, [defaultValue])
float32
Context.GetFloat64(key interface{}, [defaultValue])
float64
Context.GetString(key interface{}, [defaultValue])
string
CREATING STEPSCREATING STEPS (MAY CHANGE)(MAY CHANGE)
Create a step by implementing the interface
Example:
type StepFunc func(ctx context.Context) error
func add(ctx context.Context) error {
res := ctx.GetIntParam(0) + ctx.GetIntParam(1)
ctx.Set("sumRes", res)
return nil
}
THE CHANGESTHE CHANGES
Example:
type StepFunc func(ctx context.Context, args ...interface{}) e
func add(ctx context.Context, var1, var2 int) error {
res := var1 + var2
ctx.Set("sumRes", res)
return nil
}
HANDING ERRORSHANDING ERRORS
every step returns an error
panics are always recovered and transformed to
error
if a parameter is not defined - the test fails
func (ctx Context) Get(key interface{}, defaultValue ...interf
if _, ok := ctx.values[key]; !ok {
if len(defaultValue) == 1 {
return defaultValue[0]
}
panic(fmt.Sprintf("the key %s does not exist",
}
return ctx.values[key]
}
TESTING THE API - THETESTING THE API - THE
TESTHTTP PACKAGETESTHTTP PACKAGE
Initialization
router := http.NewServeMux()
testhttp.Build(s, router)
EXAMPLEEXAMPLE
func TestHTTP(t *testing.T) {
s := NewSuite(t, NewSuiteOptions())
router := http.NewServeMux()
router.HandleFunc("/health", func(w http.ResponseWrite
w.WriteHeader(http.StatusOK)
})
router.HandleFunc("/json", func(w http.ResponseWriter,
_, _ = w.Write([]byte(`{"valid": "json"}`))
w.WriteHeader(http.StatusOK)
})
testhttp.Build(s, router)
s.Run()
}
EXAMPLEEXAMPLE
Feature: HTTP requests
Scenario: test GET request
When I make a GET request to "/health"
Then the response code equals 200
Scenario: not existing URI
When I make a GET request to "/not-exists"
Then the response code equals 404
Scenario: testing JSON validation
When I make a GET request to "/json"
Then the response contains a valid JSON
And the response is "{"valid": "json"}"
PRE-DEFINED STEPSPRE-DEFINED STEPS
I make a
(GET|POST|PUT|DELETE|OPTIONS)
request to "([^"]*)
the response code equals (d+)
the response contains a valid JSON
the response is "(.*)"
A SMALL PACKAGE -A SMALL PACKAGE -
Available assertions:
Equals
NotEquals
ObjectsAreEqual
Nil
NotNil
ASSERTASSERT
ASSERTASSERT
func TestEqual(t *testing.T) {
if err := assert.Equals(1, 2); err == nil {
t.Error(err)
}
if err := assert.Equals(1, func() {}); err == nil {
t.Error("it shouldn't validate func in the par
}
if err := assert.Equals(5, 5); err != nil {
t.Error(err)
}
}
WEAK POINTSWEAK POINTS
WEAK POINTSWEAK POINTS
very limited pre-defined steps
WEAK POINTSWEAK POINTS
very limited pre-defined steps
not good compatibility with gherkin's output format
WHAT NEXT?WHAT NEXT?
WHAT NEXT?WHAT NEXT?
improving the testhttp package
WHAT NEXT?WHAT NEXT?
improving the testhttp package
write more packages (queues, reals API calls etc)
WHAT NEXT?WHAT NEXT?
improving the testhttp package
write more packages (queues, reals API calls etc)
implement output formats (TeamCity, JUnit etc)
WHAT NEXT?WHAT NEXT?
improving the testhttp package
write more packages (queues, reals API calls etc)
implement output formats (TeamCity, JUnit etc)
support for concurrent test execution
WHAT NEXT?WHAT NEXT?
improving the testhttp package
write more packages (queues, reals API calls etc)
implement output formats (TeamCity, JUnit etc)
support for concurrent test execution
command line parameters
WHAT NEXT?WHAT NEXT?
improving the testhttp package
write more packages (queues, reals API calls etc)
implement output formats (TeamCity, JUnit etc)
support for concurrent test execution
command line parameters
whatever will come to my mind :)
GITHUB:GITHUB:
HTTPS://GITHUB.COM/GO-HTTPS://GITHUB.COM/GO-
BDD/GOBDDBDD/GOBDD
THANK YOU!THANK YOU!
Twitter:
Email: bartlomiej.klimczak88 at gmail.com
@kabanek
developer20.com

Weitere ähnliche Inhalte

Was ist angesagt?

Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Workhorse Computing
 
jSession #4 - Maciej Puchalski - Zaawansowany retrofit
jSession #4 - Maciej Puchalski - Zaawansowany retrofitjSession #4 - Maciej Puchalski - Zaawansowany retrofit
jSession #4 - Maciej Puchalski - Zaawansowany retrofitjSession
 
Getting property based testing to work after struggling for 3 years
Getting property based testing to work after struggling for 3 yearsGetting property based testing to work after struggling for 3 years
Getting property based testing to work after struggling for 3 yearsSaurabh Nanda
 
Введение в REST API
Введение в REST APIВведение в REST API
Введение в REST APIOleg Zinchenko
 
Google Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG NantesGoogle Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG Nantesmikaelbarbero
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part AKazuchika Sekiya
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generatorsRamesh Nair
 
50 new things we can do with Java 8
50 new things we can do with Java 850 new things we can do with Java 8
50 new things we can do with Java 8José Paumard
 
Simplifying java with lambdas (short)
Simplifying java with lambdas (short)Simplifying java with lambdas (short)
Simplifying java with lambdas (short)RichardWarburton
 
JFokus 50 new things with java 8
JFokus 50 new things with java 8JFokus 50 new things with java 8
JFokus 50 new things with java 8José Paumard
 
Gogo shell
Gogo shellGogo shell
Gogo shelljwausle
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleAnton Arhipov
 
Asynchonicity: concurrency. A tale of
Asynchonicity: concurrency. A tale ofAsynchonicity: concurrency. A tale of
Asynchonicity: concurrency. A tale ofJoel Lord
 

Was ist angesagt? (19)

Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
groovy & grails - lecture 12
groovy & grails - lecture 12groovy & grails - lecture 12
groovy & grails - lecture 12
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
 
jSession #4 - Maciej Puchalski - Zaawansowany retrofit
jSession #4 - Maciej Puchalski - Zaawansowany retrofitjSession #4 - Maciej Puchalski - Zaawansowany retrofit
jSession #4 - Maciej Puchalski - Zaawansowany retrofit
 
Getting property based testing to work after struggling for 3 years
Getting property based testing to work after struggling for 3 yearsGetting property based testing to work after struggling for 3 years
Getting property based testing to work after struggling for 3 years
 
Введение в REST API
Введение в REST APIВведение в REST API
Введение в REST API
 
groovy & grails - lecture 11
groovy & grails - lecture 11groovy & grails - lecture 11
groovy & grails - lecture 11
 
Google Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG NantesGoogle Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG Nantes
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
 
50 new things we can do with Java 8
50 new things we can do with Java 850 new things we can do with Java 8
50 new things we can do with Java 8
 
Simplifying java with lambdas (short)
Simplifying java with lambdas (short)Simplifying java with lambdas (short)
Simplifying java with lambdas (short)
 
JFokus 50 new things with java 8
JFokus 50 new things with java 8JFokus 50 new things with java 8
JFokus 50 new things with java 8
 
Gogo shell
Gogo shellGogo shell
Gogo shell
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 
Asynchonicity: concurrency. A tale of
Asynchonicity: concurrency. A tale ofAsynchonicity: concurrency. A tale of
Asynchonicity: concurrency. A tale of
 

Ähnlich wie GoCracow #5 Bartlomiej klimczak - GoBDD

What's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageWhat's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageDroidConTLV
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
Groovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony CodeGroovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony Codestasimus
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Gesh Markov
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)Anders Jönsson
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes
 
Ember background basics
Ember background basicsEmber background basics
Ember background basicsPhilipp Fehre
 

Ähnlich wie GoCracow #5 Bartlomiej klimczak - GoBDD (20)

What's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageWhat's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritage
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Txjs
TxjsTxjs
Txjs
 
dojo.Patterns
dojo.Patternsdojo.Patterns
dojo.Patterns
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Google guava
Google guavaGoogle guava
Google guava
 
Groovy
GroovyGroovy
Groovy
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Groovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony CodeGroovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony Code
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
 
Ember background basics
Ember background basicsEmber background basics
Ember background basics
 

Kürzlich hochgeladen

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 

Kürzlich hochgeladen (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 

GoCracow #5 Bartlomiej klimczak - GoBDD

  • 1. HI THERE!HI THERE! I'M BARTŁOMIEJ KLIMCZAKI'M BARTŁOMIEJ KLIMCZAK #gopher #GDE #blogger
  • 3. THERE'S A LIBRARY FOR IT!THERE'S A LIBRARY FOR IT! https://github.com/DATA-DOG/godog
  • 4. ... AND THIS LIBRARY IS... AND THIS LIBRARY IS AWESOME!AWESOME!
  • 5.
  • 6. ... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC
  • 7. ... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC it runs as an external program
  • 8. ... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC it runs as an external program creates a temporary main_test file
  • 9. ... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC it runs as an external program creates a temporary main_test file it parses the temporary program's output
  • 10. ... BUT IT DOES SOME MAGIC... BUT IT DOES SOME MAGIC it runs as an external program creates a temporary main_test file it parses the temporary program's output displays the ouput in gherkin's format
  • 11. THERE'RE WEAKNESSES OF THISTHERE'RE WEAKNESSES OF THIS SOLUTIONSOLUTION doesn't use the standard testing package
  • 12. THERE'RE WEAKNESSES OF THISTHERE'RE WEAKNESSES OF THIS SOLUTIONSOLUTION doesn't use the standard testing package no good code coverage
  • 13. THERE'RE WEAKNESSES OF THISTHERE'RE WEAKNESSES OF THIS SOLUTIONSOLUTION doesn't use the standard testing package no good code coverage no debugging the test code!
  • 14. THERE'RE WEAKNESSES OF THISTHERE'RE WEAKNESSES OF THIS SOLUTIONSOLUTION doesn't use the standard testing package no good code coverage no debugging the test code! no built-in features like build tags
  • 15. THE GLOBAL STATE!THE GLOBAL STATE! // Godogs available to eat var Godogs int // somewhere in the test func FeatureContext(s *godog.Suite) { s.Step(`^there are (d+) godogs$`, thereAreGodogs) s.Step(`^I eat (d+)$`, iEat) s.Step(`^there should be (d+) remaining$`, thereShoul s.BeforeScenario(func(interface{}) { Godogs = 0 // clean the state before every sce }) }
  • 16. THAT'S WHYTHAT'S WHY EXISTSEXISTS Main goals: GOBDDGOBDD https://github.com/go-bdd/gobdd
  • 17. THAT'S WHYTHAT'S WHY EXISTSEXISTS Main goals: no magic GOBDDGOBDD https://github.com/go-bdd/gobdd
  • 18. THAT'S WHYTHAT'S WHY EXISTSEXISTS Main goals: no magic easy to use GOBDDGOBDD https://github.com/go-bdd/gobdd
  • 20. KEY FEATURES:KEY FEATURES: uses gherkin syntax uses standard testing package
  • 21. KEY FEATURES:KEY FEATURES: uses gherkin syntax uses standard testing package allows debugging and profiling the application
  • 22. KEY FEATURES:KEY FEATURES: uses gherkin syntax uses standard testing package allows debugging and profiling the application uses context between steps
  • 23. QUICK STARTQUICK START go get github.com/go-bdd/gobdd func TestScenarios(t *testing.T) { suite := gobdd.NewSuite(t) suite.AddStep(`I add (d+) and (d+)`, add) suite.AddStep(`I the result should equal (d+)`, check suite.Run() } # features/my.feature Feature: math operations Scenario: add two digits When I add 1 and 2 Then I the result should equal 3
  • 25. THE CONTEXTTHE CONTEXT holds the data from previous steps
  • 26. THE CONTEXTTHE CONTEXT holds the data from previous steps holds step's parameters fetched from the step’s definition (may change)
  • 27. THE CONTEXTTHE CONTEXT holds the data from previous steps holds step's parameters fetched from the step’s definition (may change) easier parallelism
  • 28. THE CONTEXTTHE CONTEXT holds the data from previous steps holds step's parameters fetched from the step’s definition (may change) easier parallelism The goal: hold every required information about the step itself to be successfully executed.
  • 29. THE CONTEXTTHE CONTEXT Passing information between tests // in the first step ctx.Set(name{}, "John") // in the second step fmt.Printf("Hi %sn", ctx.GetString(name{})) // prints "Hi Joh
  • 30. THE CONTEXTTHE CONTEXT List of functions for getting the data Context.GetInt(key interface{}, [defaultValue]) int Context.GetFloat32(key interface{}, [defaultValue]) float32 Context.GetFloat64(key interface{}, [defaultValue]) float64 Context.GetString(key interface{}, [defaultValue]) string
  • 31. CREATING STEPSCREATING STEPS (MAY CHANGE)(MAY CHANGE) Create a step by implementing the interface Example: type StepFunc func(ctx context.Context) error func add(ctx context.Context) error { res := ctx.GetIntParam(0) + ctx.GetIntParam(1) ctx.Set("sumRes", res) return nil }
  • 32. THE CHANGESTHE CHANGES Example: type StepFunc func(ctx context.Context, args ...interface{}) e func add(ctx context.Context, var1, var2 int) error { res := var1 + var2 ctx.Set("sumRes", res) return nil }
  • 33. HANDING ERRORSHANDING ERRORS every step returns an error panics are always recovered and transformed to error if a parameter is not defined - the test fails func (ctx Context) Get(key interface{}, defaultValue ...interf if _, ok := ctx.values[key]; !ok { if len(defaultValue) == 1 { return defaultValue[0] } panic(fmt.Sprintf("the key %s does not exist", } return ctx.values[key] }
  • 34. TESTING THE API - THETESTING THE API - THE TESTHTTP PACKAGETESTHTTP PACKAGE Initialization router := http.NewServeMux() testhttp.Build(s, router)
  • 35. EXAMPLEEXAMPLE func TestHTTP(t *testing.T) { s := NewSuite(t, NewSuiteOptions()) router := http.NewServeMux() router.HandleFunc("/health", func(w http.ResponseWrite w.WriteHeader(http.StatusOK) }) router.HandleFunc("/json", func(w http.ResponseWriter, _, _ = w.Write([]byte(`{"valid": "json"}`)) w.WriteHeader(http.StatusOK) }) testhttp.Build(s, router) s.Run() }
  • 36. EXAMPLEEXAMPLE Feature: HTTP requests Scenario: test GET request When I make a GET request to "/health" Then the response code equals 200 Scenario: not existing URI When I make a GET request to "/not-exists" Then the response code equals 404 Scenario: testing JSON validation When I make a GET request to "/json" Then the response contains a valid JSON And the response is "{"valid": "json"}"
  • 37. PRE-DEFINED STEPSPRE-DEFINED STEPS I make a (GET|POST|PUT|DELETE|OPTIONS) request to "([^"]*) the response code equals (d+) the response contains a valid JSON the response is "(.*)"
  • 38. A SMALL PACKAGE -A SMALL PACKAGE - Available assertions: Equals NotEquals ObjectsAreEqual Nil NotNil ASSERTASSERT
  • 39. ASSERTASSERT func TestEqual(t *testing.T) { if err := assert.Equals(1, 2); err == nil { t.Error(err) } if err := assert.Equals(1, func() {}); err == nil { t.Error("it shouldn't validate func in the par } if err := assert.Equals(5, 5); err != nil { t.Error(err) } }
  • 41. WEAK POINTSWEAK POINTS very limited pre-defined steps
  • 42. WEAK POINTSWEAK POINTS very limited pre-defined steps not good compatibility with gherkin's output format
  • 44. WHAT NEXT?WHAT NEXT? improving the testhttp package
  • 45. WHAT NEXT?WHAT NEXT? improving the testhttp package write more packages (queues, reals API calls etc)
  • 46. WHAT NEXT?WHAT NEXT? improving the testhttp package write more packages (queues, reals API calls etc) implement output formats (TeamCity, JUnit etc)
  • 47. WHAT NEXT?WHAT NEXT? improving the testhttp package write more packages (queues, reals API calls etc) implement output formats (TeamCity, JUnit etc) support for concurrent test execution
  • 48. WHAT NEXT?WHAT NEXT? improving the testhttp package write more packages (queues, reals API calls etc) implement output formats (TeamCity, JUnit etc) support for concurrent test execution command line parameters
  • 49. WHAT NEXT?WHAT NEXT? improving the testhttp package write more packages (queues, reals API calls etc) implement output formats (TeamCity, JUnit etc) support for concurrent test execution command line parameters whatever will come to my mind :)
  • 51. THANK YOU!THANK YOU! Twitter: Email: bartlomiej.klimczak88 at gmail.com @kabanek developer20.com