SlideShare a Scribd company logo
Specs  _ what it is Scala library for Behaviour-Driven Development. See the  associated code  for a working example - HelloWorldSpec.scala import  org.specs._ object  HelloWorldSpec  extends   Specification  { "'hello world' has 11 characters"   in  {  "hello world" .size must_== 11 } "'hello world' matches 'h.* w.*'"   in  {  "hello world"  must beMatching( "h.* w.*" ) } } [info] Running specs tests... [info]  [info] Testing scalamelb.specs.HelloWorldSpec ... [info]  specifies  [info]  + 'hello world' has 11 characters [info]  + 'hello world' matches 'h.* w.*' [info]  [info] All tests PASSED.
Specs  _ structure BDD builds on TDD to allow tests to be written in the business domain language.
The Specs structure:  Specify  system  (with context)   and  examples "An empty stack" should "be of size zero" NigerianPrinceSpec.scala "A Nigerian prince with access to an email account"   should  { "contact you in relation to his most generous offer"   in  { // exercise the logic and make assertions ... } }
Specs  _ structure Examples can be nested
Systems can't
Specifications can, sort of SnowflakeSpec.scala "A snowflake"   should  {  [info]  A snowflake should "be cold"   in  {  [info]  + be cold "and icy"   in  { … }  [info]  + and icy "and unique"   in  { … }  [info]  + and unique "A snowflake"   should  { "in the desert"   should  { "melt"   in  { … } object  SnowflakeSpec  extends   Specification  { "A snowflake"   isSpecifiedBy   SnowflakeInTheDesertSpec ,  SnowflakeInTheFrideSpec , SnowflakeOnTheTongueSpec }
Specs  _ matchers Matchers are the assertion mechanism. Allow natural language assertions
100+ are documented at time of writing  (v1.4.4)
Can write custom matchers. Can be combinatorial. PhoneBillSpec.scala "A phone bill"   should  { "keep a count of calls made"   in  { bill.numberOfCallsMade  must_==  3 "A phone bill"   should  { "include a call to my mother"   in  { bill.callsMade  must contain ("9898 4477") "A phone bill"   should  { "export calls to file"   in  { bill.exportFile  must (beReadable and not(beHidden))
Specs  _ scalacheck Matcher for  ScalaCheck (A test case automation tool)

More Related Content

PDF
Zeppelin Helium: Spell
PDF
ES6 Simplified
PDF
Hidden Gems of Ruby 1.9
PDF
Design Summit - Rails 4 Migration - Aaron Patterson
ODP
Back to basics - PHP_Codesniffer
ODP
What's new in Perl 5.10?
PDF
The Ring programming language version 1.9 book - Part 95 of 210
KEY
10 Catalyst Tips
Zeppelin Helium: Spell
ES6 Simplified
Hidden Gems of Ruby 1.9
Design Summit - Rails 4 Migration - Aaron Patterson
Back to basics - PHP_Codesniffer
What's new in Perl 5.10?
The Ring programming language version 1.9 book - Part 95 of 210
10 Catalyst Tips

What's hot (19)

KEY
Elegant APIs
KEY
Zen: Building Maintainable Catalyst Applications
PPTX
C to perl binding
PPTX
Python Programming Essentials - M27 - Logging module
PPTX
Python Programming Essentials - M35 - Iterators & Generators
PDF
Desenvolvendo em php cli
PDF
Four Ways to add Features to Ext JS
PDF
Bee Smalltalk RunTime: anchor's aweigh
PPTX
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
PPT
Test::Base
PDF
Symfony 4 Workshop - Limenius
PPTX
Oop object oriented programing topics
PPT
Sencha Touch Intro
PDF
Crossing the Bridge: Connecting Rails and your Front-end Framework
PDF
Ansible Callback Plugins
PDF
Testing Ruby with Rspec (a beginner's guide)
PPTX
MUST CS101 Lab11
ODP
Java Boilerplate Busters
PDF
AOP in Python API design
Elegant APIs
Zen: Building Maintainable Catalyst Applications
C to perl binding
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M35 - Iterators & Generators
Desenvolvendo em php cli
Four Ways to add Features to Ext JS
Bee Smalltalk RunTime: anchor's aweigh
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Test::Base
Symfony 4 Workshop - Limenius
Oop object oriented programing topics
Sencha Touch Intro
Crossing the Bridge: Connecting Rails and your Front-end Framework
Ansible Callback Plugins
Testing Ruby with Rspec (a beginner's guide)
MUST CS101 Lab11
Java Boilerplate Busters
AOP in Python API design
Ad

Viewers also liked (20)

PPT
What is Residual solvent and its identification
PDF
Impurities in DS & DP
PPT
NDA ANDA IND by Anthony Crasto
PPSX
Residual Solvent Limit Calculation
PPTX
Handling of Out of Specification Results
PPT
Dissolution-method Development-PPT
PPTX
Out of specification shravan
PPT
Impurities
PPTX
Recent advancement in impurity profiling
PPTX
Dissolution Method Development & Validation
PDF
NDA & ANDA approval
PPTX
Impurities in drug substance (ich q3 a)
PPTX
Out of specification (oos)1
PPT
ABBREVIATED NEW DRUG APPLICATION (ANDA) by Anthony crasto
PPTX
Method Development and Method Validation for the estimation of Valganciclovir...
PDF
Analytical method validation by manoj ingale(best ppts)
PPT
analytical method validation
PPT
analytical method validation and validation of hplc
PPT
Analytical method validation
PPTX
ANDA filing
What is Residual solvent and its identification
Impurities in DS & DP
NDA ANDA IND by Anthony Crasto
Residual Solvent Limit Calculation
Handling of Out of Specification Results
Dissolution-method Development-PPT
Out of specification shravan
Impurities
Recent advancement in impurity profiling
Dissolution Method Development & Validation
NDA & ANDA approval
Impurities in drug substance (ich q3 a)
Out of specification (oos)1
ABBREVIATED NEW DRUG APPLICATION (ANDA) by Anthony crasto
Method Development and Method Validation for the estimation of Valganciclovir...
Analytical method validation by manoj ingale(best ppts)
analytical method validation
analytical method validation and validation of hplc
Analytical method validation
ANDA filing
Ad

Similar to Specs Presentation (20)

PPTX
Scala 3camp 2011
PPTX
JavaScript, Beyond the Curly Braces
PPT
Testing Javascript with Jasmine
PPTX
JavaScript Sprachraum
PPT
Exploiting Php With Php
PPT
Jsp And Jdbc
PPTX
Build Lightweight Web Module
PPT
Falcon初印象
PPT
JDBC Java Database Connectivity
ODP
Drools BeJUG 2010
ODP
Domain Specific Languages In Scala Duse3
PPT
C++ programming
PPT
Python - Getting to the Essence - Points.com - Dave Park
PPTX
Maker All - Executive Presentation
PPT
Spring Capitulo 05
PPT
ODP
Scala 2 + 2 > 4
PPTX
Xenogenetics for PL/SQL - infusing with Java best practices
PPTX
Xenogenetics
PPT
On Scala Slides - OSDC 2009
Scala 3camp 2011
JavaScript, Beyond the Curly Braces
Testing Javascript with Jasmine
JavaScript Sprachraum
Exploiting Php With Php
Jsp And Jdbc
Build Lightweight Web Module
Falcon初印象
JDBC Java Database Connectivity
Drools BeJUG 2010
Domain Specific Languages In Scala Duse3
C++ programming
Python - Getting to the Essence - Points.com - Dave Park
Maker All - Executive Presentation
Spring Capitulo 05
Scala 2 + 2 > 4
Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics
On Scala Slides - OSDC 2009

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Spectroscopy.pptx food analysis technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
MIND Revenue Release Quarter 2 2025 Press Release
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Understanding_Digital_Forensics_Presentation.pptx
MYSQL Presentation for SQL database connectivity
Mobile App Security Testing_ A Comprehensive Guide.pdf
Review of recent advances in non-invasive hemoglobin estimation
Unlocking AI with Model Context Protocol (MCP)
Spectroscopy.pptx food analysis technology
Dropbox Q2 2025 Financial Results & Investor Presentation
sap open course for s4hana steps from ECC to s4
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
The AUB Centre for AI in Media Proposal.docx
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Specs Presentation

  • 1. Specs _ what it is Scala library for Behaviour-Driven Development. See the associated code for a working example - HelloWorldSpec.scala import org.specs._ object HelloWorldSpec extends Specification { "'hello world' has 11 characters" in { "hello world" .size must_== 11 } "'hello world' matches 'h.* w.*'" in { "hello world" must beMatching( "h.* w.*" ) } } [info] Running specs tests... [info] [info] Testing scalamelb.specs.HelloWorldSpec ... [info] specifies [info] + 'hello world' has 11 characters [info] + 'hello world' matches 'h.* w.*' [info] [info] All tests PASSED.
  • 2. Specs _ structure BDD builds on TDD to allow tests to be written in the business domain language.
  • 3. The Specs structure: Specify system (with context) and examples "An empty stack" should "be of size zero" NigerianPrinceSpec.scala "A Nigerian prince with access to an email account" should { "contact you in relation to his most generous offer" in { // exercise the logic and make assertions ... } }
  • 4. Specs _ structure Examples can be nested
  • 6. Specifications can, sort of SnowflakeSpec.scala "A snowflake" should { [info] A snowflake should "be cold" in { [info] + be cold "and icy" in { … } [info] + and icy "and unique" in { … } [info] + and unique "A snowflake" should { "in the desert" should { "melt" in { … } object SnowflakeSpec extends Specification { "A snowflake" isSpecifiedBy SnowflakeInTheDesertSpec , SnowflakeInTheFrideSpec , SnowflakeOnTheTongueSpec }
  • 7. Specs _ matchers Matchers are the assertion mechanism. Allow natural language assertions
  • 8. 100+ are documented at time of writing (v1.4.4)
  • 9. Can write custom matchers. Can be combinatorial. PhoneBillSpec.scala "A phone bill" should { "keep a count of calls made" in { bill.numberOfCallsMade must_== 3 "A phone bill" should { "include a call to my mother" in { bill.callsMade must contain ("9898 4477") "A phone bill" should { "export calls to file" in { bill.exportFile must (beReadable and not(beHidden))
  • 10. Specs _ scalacheck Matcher for ScalaCheck (A test case automation tool)
  • 11. Default of 100 arbitrary test input values per statement
  • 12. For all n (where n >=0) √n² must equal n SquareRooter.scala object SquareRooterSpec extends Specification with ScalaCheck { "A Square Rooter" should { "find the originally squared value (as long as it wasn't negative)" in { // forAll { (n: Int) => scala.Math.sqrt(n*n) == n } must pass // fails on -1 forAll { n: Int => n >= 0 ==> (scala.Math.sqrt(n*n) == n) } must pass
  • 13. Specs _ tear up / down Traditional setup & teardown mechanisms available for before and after: Specification
  • 15. each Example SetupAndTeardown.scala object SetupAndTeardown extends Specification { doBeforeSpec{ println( "Specification setup" ) } doFirst{ println( "System setup" ) } doBefore{ println( "Example setup" ) } … doAfter{ println( "example teardown" ) } doLast{ println( "System teardown" ) } doAfterSpec{ println( "Specification teardown" ) } }
  • 16. Specs _ shared contexts Before and after context blocks can be encapsulated in Context values and "threaded" into Systems.
  • 17. They come with a warning – expect the unexpected if shared and mutated in different Systems within the Specification. And don't feed after midnight. ThreadedLists.scala var listOfStrings:List[ String ] = Nil val withThreeValues = beforeContext { listOfStrings = "bob" :: "harry" :: "dorothy" :: Nil } "A list of three Strings" ->-(withThreeValues) should { "be of three strings long" in { listOfStrings.length must_== 3 } }
  • 18. Specs _ system contexts Alternatively, System Contexts can be constructed to always return a system in a given state.
  • 19. They come in two flavours: Internal (a SystemContext instance)
  • 20. External (a case class extending SystemContext) MonkeyKing.scala object MonkeyKingSpec extends Specification with SystemContexts { /* Demonstrates explicit, internal system context. See example for more. */ "The monkey king under attack" should { val monkeyKingUnderAttack = systemContext { new MonkeyKing ( true ) } "summon warriors from his ear hairs" .withA(monkeyKingUnderAttack) { monkeyKing => monkeyKing.summonsWarriorsFromEarHair must beTrue
  • 21. Specs _ mocking Both jMock and Mockito can be mixed-in Specs adds syntactic sugar to ease mocking USBLightSpec.scala object USBLightSpec extends Specification with Mockito { "A green USB light" should { "be observed but not adjusted" in { val light = mock[ Light ] light.getColour returns Green val colour = LightObserver(light).observeLightsColour colour must_== Green light.getColour was called light.setIntensity _ wasnt called
  • 22. Specs _ alternatives ScalaTest
  • 23. Instinct class StackSpec extends Spec with ShouldMatchers { describe( "A newly created Stack" ) { val stack = new Stack[Any] it( "should be empty" ) { stack should be ('empty) } } } class ANewlyCreatedStack { val stack = new Stack[Any] @Specification def shouldBeEmpty = { expect that stack.depth isEqualTo 0 } }