SlideShare a Scribd company logo
1 of 9
Download to read offline
Spock Framework
писать тесты просто
Aндрей Малыхин, Яндекс
Spock Framework
2
Specification testing framework for Java and Groovy applications.
BDD testing?!
3
BDD = TDD + (Dan North + “standard agile framework”)
User story: “As a [role] I want [feature] so that [benefit]”
Test scenario:
given [initial context],
when [event occurs],
then [ensure some outcomes]
public class SuperTypeForGeneratedTestCase {

private Author createAuthor() throws InstantiationException, IllegalAccessException {



Author author = EasyMock.createNiceMock(AuthorParent.class);

EasyMock.expect(author.getName()).andReturn("Khalil Gebran").anyTimes();

EasyMock.replay(author);



return author;

}



private Book createBook() throws InstantiationException, IllegalAccessException {

Book book = EasyMock.createNiceMock(BookParent.class);

EasyMock.expect(book.getTitle()).andReturn("The Prophet").anyTimes();

Author author = createAuthor();

EasyMock.expect(book.getAuthor()).andReturn(author).anyTimes();

EasyMock.replay(book);



return book;

}



private Library createLibrary() throws InstantiationException, IllegalAccessException {



Library lib = EasyMock.createNiceMock(LibraryParent.class);

EasyMock.expect(lib.getTitle()).andReturn("Test Library").anyTimes();

List<Book> books = new ArrayList<Book>();

Book book = createBook();

books.add(book);

EasyMock.expect(lib.getBooks()).andReturn(books).anyTimes();



EasyMock.replay(lib);



return lib;

}



@Test

public void testSuperTypeMappingForInaccessibleClasses() throws Exception {



MapperFactory factory = MappingUtil.getMapperFactory();



Library lib = createLibrary();

Book book = lib.getBooks().get(0);



LibraryDTO mappedLib = factory.getMapperFacade(Library.class, LibraryDTO.class).map(lib);



Assert.assertNotNull(mappedLib);



Assert.assertEquals(lib.getTitle(),mappedLib.getTitle());

Assert.assertEquals(book.getTitle(),mappedLib.getBooks().get(0).getTitle());

Assert.assertEquals(book.getAuthor().getName(),mappedLib.getBooks().get(0).getAuthor().getName());

}

}
Проблема?
public class SuperTypeForGeneratedTestCase {

private Author createAuthor() throws InstantiationException, IllegalAccessException {



Author author = EasyMock.createNiceMock(AuthorParent.class);

EasyMock.expect(author.getName()).andReturn("Khalil Gebran").anyTimes();

EasyMock.replay(author);



return author;

}



private Book createBook() throws InstantiationException, IllegalAccessException {

Book book = EasyMock.createNiceMock(BookParent.class);

EasyMock.expect(book.getTitle()).andReturn("The Prophet").anyTimes();

Author author = createAuthor();

EasyMock.expect(book.getAuthor()).andReturn(author).anyTimes();

EasyMock.replay(book);



return book;

}



private Library createLibrary() throws InstantiationException, IllegalAccessException {



Library lib = EasyMock.createNiceMock(LibraryParent.class);

EasyMock.expect(lib.getTitle()).andReturn("Test Library").anyTimes();

List<Book> books = new ArrayList<Book>();

Book book = createBook();

books.add(book);

EasyMock.expect(lib.getBooks()).andReturn(books).anyTimes();



EasyMock.replay(lib);



return lib;

}



@Test

public void testSuperTypeMappingForInaccessibleClasses() throws Exception {



MapperFactory factory = MappingUtil.getMapperFactory();



Library lib = createLibrary();

Book book = lib.getBooks().get(0);



LibraryDTO mappedLib = factory.getMapperFacade(Library.class, LibraryDTO.class).map(lib);



Assert.assertNotNull(mappedLib);



Assert.assertEquals(lib.getTitle(),mappedLib.getTitle());

Assert.assertEquals(book.getTitle(),mappedLib.getBooks().get(0).getTitle());

Assert.assertEquals(book.getAuthor().getName(),mappedLib.getBooks().get(0).getAuthor().getName());

}

}
class SuperTypeForGeneratedSpec extends Specification {

def "mapping by supper type should work for inaccessible class"() {

given:

def factory = MappingUtil.getMapperFactory()

and:

def lib = Mock(Model.LibraryParent) {

getTitle() >> 'Test Library'

getBooks() >> [Mock(Model.Book) {

getTitle() >> 'The Prophet'

getAuthor() >> Mock(Model.Author) {

getName() >> 'Khalil Gebran'

}

}]

};



when:

def actual = factory.getMapperFacade(Model.Library,Model.LibraryDTO).map(lib)



then:
actual

actual.title == lib.title

actual.books[0].title == lib.books[0].title

actual.books[0].author.name == lib.books[0].author.name

}

}
How can we do better?
Demo
Go to Production
7
on Groovy & Spock
We start to write tests…
Live long and prosper.
@katoquro bitbucket.org/katoquro/spock-demo
Ссылки
〉Spock Framework Docs bit.ly/spock-docs-1
〉Spock Framework Source github.com/spockframework
〉Demo Code bitbucket.org/katoquro/spock-demo
〉Star Trek TOS bit.ly/star-trek-tos

More Related Content

What's hot

System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspmJesse Warden
 
Unirest Java Tutorial | Java Http Client
Unirest Java Tutorial | Java Http ClientUnirest Java Tutorial | Java Http Client
Unirest Java Tutorial | Java Http Clientrahul patel
 
Browser testing with nightwatch.js - Drupal Europe
Browser testing with nightwatch.js - Drupal EuropeBrowser testing with nightwatch.js - Drupal Europe
Browser testing with nightwatch.js - Drupal EuropeSalvador Molina (Slv_)
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
DalekJS Workshop at T3DD14
DalekJS Workshop at T3DD14DalekJS Workshop at T3DD14
DalekJS Workshop at T3DD14Peter Foerger
 
Web Developing In Search
Web Developing In SearchWeb Developing In Search
Web Developing In SearchFrank Xu
 
Dalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptDalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptNir Elbaz
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejsAmit Thakkar
 
Spring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsSpring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsArawn Park
 
Product Ecosystem Of Cloud Native Applications
Product Ecosystem Of Cloud Native ApplicationsProduct Ecosystem Of Cloud Native Applications
Product Ecosystem Of Cloud Native ApplicationsRaja Soundaramourty
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introductionSergii Fesenko
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 

What's hot (20)

System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
 
Node.js 0.8 features
Node.js 0.8 featuresNode.js 0.8 features
Node.js 0.8 features
 
Unirest Java Tutorial | Java Http Client
Unirest Java Tutorial | Java Http ClientUnirest Java Tutorial | Java Http Client
Unirest Java Tutorial | Java Http Client
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
 
Browser testing with nightwatch.js - Drupal Europe
Browser testing with nightwatch.js - Drupal EuropeBrowser testing with nightwatch.js - Drupal Europe
Browser testing with nightwatch.js - Drupal Europe
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
DalekJS Workshop at T3DD14
DalekJS Workshop at T3DD14DalekJS Workshop at T3DD14
DalekJS Workshop at T3DD14
 
Web Developing In Search
Web Developing In SearchWeb Developing In Search
Web Developing In Search
 
Dalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptDalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScript
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
Zen of Akka
Zen of AkkaZen of Akka
Zen of Akka
 
Spring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsSpring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trends
 
Product Ecosystem Of Cloud Native Applications
Product Ecosystem Of Cloud Native ApplicationsProduct Ecosystem Of Cloud Native Applications
Product Ecosystem Of Cloud Native Applications
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
 
Node.js debugging
Node.js debuggingNode.js debugging
Node.js debugging
 
ZODB Tips and Tricks
ZODB Tips and TricksZODB Tips and Tricks
ZODB Tips and Tricks
 
Nashorn
NashornNashorn
Nashorn
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
hacking with node.JS
hacking with node.JShacking with node.JS
hacking with node.JS
 

Similar to Spock Framework (Java Day BY 2015)

Microsrvs testing-slides
Microsrvs testing-slidesMicrosrvs testing-slides
Microsrvs testing-slidesIgor Redkach
 
[@IndeedEng] Building Indeed Resume Search
[@IndeedEng] Building Indeed Resume Search[@IndeedEng] Building Indeed Resume Search
[@IndeedEng] Building Indeed Resume Searchindeedeng
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
Arquillian Constellation
Arquillian ConstellationArquillian Constellation
Arquillian ConstellationAlex Soto
 
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Codemotion
 
Android testing
Android testingAndroid testing
Android testingSean Tsai
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationRichard North
 
G*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIIG*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIITakuma Watabiki
 
Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmineRubyc Slides
 
Improving your Gradle builds
Improving your Gradle buildsImproving your Gradle builds
Improving your Gradle buildsPeter Ledbrook
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPAFaren faren
 
Das kannste schon so machen
Das kannste schon so machenDas kannste schon so machen
Das kannste schon so machenAndré Goliath
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javacAnna Brzezińska
 
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!Liwei Chou
 
Writing automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsWriting automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsLeticia Rss
 

Similar to Spock Framework (Java Day BY 2015) (20)

Microsrvs testing-slides
Microsrvs testing-slidesMicrosrvs testing-slides
Microsrvs testing-slides
 
[@IndeedEng] Building Indeed Resume Search
[@IndeedEng] Building Indeed Resume Search[@IndeedEng] Building Indeed Resume Search
[@IndeedEng] Building Indeed Resume Search
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Arquillian Constellation
Arquillian ConstellationArquillian Constellation
Arquillian Constellation
 
Latinoware
LatinowareLatinoware
Latinoware
 
Spock
SpockSpock
Spock
 
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
 
Spock
SpockSpock
Spock
 
Android testing
Android testingAndroid testing
Android testing
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
 
G*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIIG*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIII
 
Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmine
 
Improving your Gradle builds
Improving your Gradle buildsImproving your Gradle builds
Improving your Gradle builds
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
Das kannste schon so machen
Das kannste schon so machenDas kannste schon so machen
Das kannste schon so machen
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
 
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
 
Writing automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsWriting automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjects
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Spock Framework (Java Day BY 2015)

  • 1. Spock Framework писать тесты просто Aндрей Малыхин, Яндекс
  • 2. Spock Framework 2 Specification testing framework for Java and Groovy applications.
  • 3. BDD testing?! 3 BDD = TDD + (Dan North + “standard agile framework”) User story: “As a [role] I want [feature] so that [benefit]” Test scenario: given [initial context], when [event occurs], then [ensure some outcomes]
  • 4. public class SuperTypeForGeneratedTestCase {
 private Author createAuthor() throws InstantiationException, IllegalAccessException {
 
 Author author = EasyMock.createNiceMock(AuthorParent.class);
 EasyMock.expect(author.getName()).andReturn("Khalil Gebran").anyTimes();
 EasyMock.replay(author);
 
 return author;
 }
 
 private Book createBook() throws InstantiationException, IllegalAccessException {
 Book book = EasyMock.createNiceMock(BookParent.class);
 EasyMock.expect(book.getTitle()).andReturn("The Prophet").anyTimes();
 Author author = createAuthor();
 EasyMock.expect(book.getAuthor()).andReturn(author).anyTimes();
 EasyMock.replay(book);
 
 return book;
 }
 
 private Library createLibrary() throws InstantiationException, IllegalAccessException {
 
 Library lib = EasyMock.createNiceMock(LibraryParent.class);
 EasyMock.expect(lib.getTitle()).andReturn("Test Library").anyTimes();
 List<Book> books = new ArrayList<Book>();
 Book book = createBook();
 books.add(book);
 EasyMock.expect(lib.getBooks()).andReturn(books).anyTimes();
 
 EasyMock.replay(lib);
 
 return lib;
 }
 
 @Test
 public void testSuperTypeMappingForInaccessibleClasses() throws Exception {
 
 MapperFactory factory = MappingUtil.getMapperFactory();
 
 Library lib = createLibrary();
 Book book = lib.getBooks().get(0);
 
 LibraryDTO mappedLib = factory.getMapperFacade(Library.class, LibraryDTO.class).map(lib);
 
 Assert.assertNotNull(mappedLib);
 
 Assert.assertEquals(lib.getTitle(),mappedLib.getTitle());
 Assert.assertEquals(book.getTitle(),mappedLib.getBooks().get(0).getTitle());
 Assert.assertEquals(book.getAuthor().getName(),mappedLib.getBooks().get(0).getAuthor().getName());
 }
 } Проблема?
  • 5. public class SuperTypeForGeneratedTestCase {
 private Author createAuthor() throws InstantiationException, IllegalAccessException {
 
 Author author = EasyMock.createNiceMock(AuthorParent.class);
 EasyMock.expect(author.getName()).andReturn("Khalil Gebran").anyTimes();
 EasyMock.replay(author);
 
 return author;
 }
 
 private Book createBook() throws InstantiationException, IllegalAccessException {
 Book book = EasyMock.createNiceMock(BookParent.class);
 EasyMock.expect(book.getTitle()).andReturn("The Prophet").anyTimes();
 Author author = createAuthor();
 EasyMock.expect(book.getAuthor()).andReturn(author).anyTimes();
 EasyMock.replay(book);
 
 return book;
 }
 
 private Library createLibrary() throws InstantiationException, IllegalAccessException {
 
 Library lib = EasyMock.createNiceMock(LibraryParent.class);
 EasyMock.expect(lib.getTitle()).andReturn("Test Library").anyTimes();
 List<Book> books = new ArrayList<Book>();
 Book book = createBook();
 books.add(book);
 EasyMock.expect(lib.getBooks()).andReturn(books).anyTimes();
 
 EasyMock.replay(lib);
 
 return lib;
 }
 
 @Test
 public void testSuperTypeMappingForInaccessibleClasses() throws Exception {
 
 MapperFactory factory = MappingUtil.getMapperFactory();
 
 Library lib = createLibrary();
 Book book = lib.getBooks().get(0);
 
 LibraryDTO mappedLib = factory.getMapperFacade(Library.class, LibraryDTO.class).map(lib);
 
 Assert.assertNotNull(mappedLib);
 
 Assert.assertEquals(lib.getTitle(),mappedLib.getTitle());
 Assert.assertEquals(book.getTitle(),mappedLib.getBooks().get(0).getTitle());
 Assert.assertEquals(book.getAuthor().getName(),mappedLib.getBooks().get(0).getAuthor().getName());
 }
 } class SuperTypeForGeneratedSpec extends Specification {
 def "mapping by supper type should work for inaccessible class"() {
 given:
 def factory = MappingUtil.getMapperFactory()
 and:
 def lib = Mock(Model.LibraryParent) {
 getTitle() >> 'Test Library'
 getBooks() >> [Mock(Model.Book) {
 getTitle() >> 'The Prophet'
 getAuthor() >> Mock(Model.Author) {
 getName() >> 'Khalil Gebran'
 }
 }]
 };
 
 when:
 def actual = factory.getMapperFacade(Model.Library,Model.LibraryDTO).map(lib)
 
 then: actual
 actual.title == lib.title
 actual.books[0].title == lib.books[0].title
 actual.books[0].author.name == lib.books[0].author.name
 }
 } How can we do better?
  • 7. Go to Production 7 on Groovy & Spock We start to write tests…
  • 8. Live long and prosper. @katoquro bitbucket.org/katoquro/spock-demo
  • 9. Ссылки 〉Spock Framework Docs bit.ly/spock-docs-1 〉Spock Framework Source github.com/spockframework 〉Demo Code bitbucket.org/katoquro/spock-demo 〉Star Trek TOS bit.ly/star-trek-tos