SlideShare a Scribd company logo
1 of 19
Property-based testing with Java
By Franck Benault
Created 06/07/2016
Last update 10/08/2016
Property-based testing introduction
● Tests = often (or should be) only one example
– We can say « Example-based testing »
@Test
TestFoo() { //no parameters
//my code of test
Int x =1 ;
Int res =foo(x) ;
Assert(..)
}
● Yes but if my test is ok for x=1, is it ok for x=25 ?
Property-based testing introduction
● Property based testing is
– Based on existing check
– Randomly generate a lot of input parameter
● Which satisfy predefined properties
@Test
TestFoo2(String s1, int x ) { //parameters !
//my code of test
int res =foo(x) ; //the parameter are used in the test
Assert(..)
}
Property-based testing plan
Property-based testing introduction
● Property based testing functionalities
– Tests with parameters
● Values of parameters (randonly or following an order) generated
– N times
● Values of parameters satisfying properties
– >0, <0
– Filter of the bad values (« assume »)
● Seed value
– Value that allow us to relaunch the tests with the same random values
● Shrinking
– If the test fails, the framework tries to find the lowest values which fail
the test
Property-based testing links
● My examples in Github
– https://github.com/franck-benault/property-based-testing
● Other links
– http://www.ontestautomation.com/an-introduction-to-property
● Good introduction
Seed and Shrinking
● Shrinking
– If the test fails, repeat the test until it finds the simpliest
test case that still fails
● Seed
– There is a random generation
– But the seed value allows us to reproduce the exact
same run
– The seed value is the only source of randomness
Goal of this presentation
● Goal (in java world)
– Limitation of the classical test
– Simple presentation of property based testing
– First Comparison of the main tools
– Notion of seed and shrinking
Remind over Assume in JUnit
● Assume = assumption
– Ignore if it fails
– In method @BeforeClass, @Before, @Test
– Possible assumption
● AssumeTrue
● AssumeEquals, AssumeSame
● AssumeNull, AssumeNotNull
● AssumeThat (matcher)
Annotation @Theory of JUnit
● Annotation @Theory
– since Junit 4.4
– Junit only (not testNG)
– Specific Runner (class Theories)
● But all the junit functionalities are honored
– @Test, @Before, @After, @BeforeClass, @AfterClass
● Two parts
– Data creation
– Theory (test with parameters and @Theory)
Annotation @Theory of JUnit
● Data creation
– Annotations
● Datapoint (on value)
● Datapoints (on tabs public static method or variable)
● FromDataPoints annotation
● TestedOn (on parameters type int)
● It is possible to write your own annotations
● Theory (test with parameters and @Theory)
– Parameter nullsAccepted
Annotation @Theory of JUnit
● Limitation
– Experimental package
– No advanced data generation
● No random values
– No seed, no shrinking
– Known bug with enumerations
Junit-Quickcheck
● Junit-Quickcheck
– Property based testing for Java
– Runner = JUnitQuickcheck
– Random data generated
– Test annotated with @Property
● Variable trials (number of tests default = 100)
– Seed and Shrinking
Junit-Quickcheck
● Basic type supported random generation
– Primitives (int, boolean ...)
– String ...
● Annotation ValuesOf
– Enum, boolean (no random generation, sequential generation)
● Annotation @InRange (min , max)
– integer
● Possible to write our own generator
– @From(XXX.class)
● where XXX is an extension of Generator
Junit-Quickcheck
● Limitations
– java8 only
– Junit only (not testNG)
– Shrinking is not working well
Quicktheory
● Quickcheck
– Junit or TestNG
– The loop is inside the test (default loop of 1000 times)
● qt.forAll(...)
● Random generation (with seed option)
– Assumption using assuming method
● The loop size is still 1000
– Seed and shrinking working fine
Quicktheory generator and source
● Integer / long generation
– All, AllPositive (for integer only), between
– More possibilities using assuming
● Float / Double
– All, from 0 to 1, positive, negative
● Boolean
– All
● You can define your own source and generator
Quicktheory
● Limitations
– Less integrated in the test framework
– java8 only
– Lack of documentation
Conclusion
● Useful for the robustness tests ?

More Related Content

Viewers also liked

Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockitoMathieu Carbou
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentjakubkoci
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest MatchersShai Yallin
 
JUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJohn Ferguson Smart Limited
 
Model-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelModel-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelBob Binder
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondSam Brannen
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with MockitoRichard Paul
 

Viewers also liked (8)

Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest Matchers
 
Mockito
MockitoMockito
Mockito
 
JUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit Tests
 
Model-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelModel-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next Level
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyond
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
 

Similar to Property based-testing

ScalaCheck
ScalaCheckScalaCheck
ScalaCheckBeScala
 
Test in action week 4
Test in action   week 4Test in action   week 4
Test in action week 4Yi-Huan Chan
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2Yi-Huan Chan
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.jsRotem Tamir
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)Steve Upton
 
Effective Readable unit testing with junit5
Effective Readable unit testing with junit5Effective Readable unit testing with junit5
Effective Readable unit testing with junit5Sajith Vijesekara
 
Be smart when testing your Akka code
Be smart when testing your Akka codeBe smart when testing your Akka code
Be smart when testing your Akka codeMykhailo Kotsur
 
Java2 days 2013-j-treg
Java2 days 2013-j-tregJava2 days 2013-j-treg
Java2 days 2013-j-tregMani Sarkar
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Codemotion
 
Not Your Mommas Unit Tests - Parameterized Unit Tests
Not Your Mommas Unit Tests - Parameterized Unit TestsNot Your Mommas Unit Tests - Parameterized Unit Tests
Not Your Mommas Unit Tests - Parameterized Unit TestsBill Shelton
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with JunitValerio Maggio
 

Similar to Property based-testing (20)

ScalaCheck
ScalaCheckScalaCheck
ScalaCheck
 
Test in action week 4
Test in action   week 4Test in action   week 4
Test in action week 4
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
Effective Readable unit testing with junit5
Effective Readable unit testing with junit5Effective Readable unit testing with junit5
Effective Readable unit testing with junit5
 
Be smart when testing your Akka code
Be smart when testing your Akka codeBe smart when testing your Akka code
Be smart when testing your Akka code
 
ppopoff
ppopoffppopoff
ppopoff
 
Junit basics
Junit basicsJunit basics
Junit basics
 
Angular testing
Angular testingAngular testing
Angular testing
 
Java2 days 2013-j-treg
Java2 days 2013-j-tregJava2 days 2013-j-treg
Java2 days 2013-j-treg
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018
 
Lazy java
Lazy javaLazy java
Lazy java
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Not Your Mommas Unit Tests - Parameterized Unit Tests
Not Your Mommas Unit Tests - Parameterized Unit TestsNot Your Mommas Unit Tests - Parameterized Unit Tests
Not Your Mommas Unit Tests - Parameterized Unit Tests
 
Good Practices On Test Automation
Good Practices On Test AutomationGood Practices On Test Automation
Good Practices On Test Automation
 
Unit testing with java
Unit testing with javaUnit testing with java
Unit testing with java
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
 

More from fbenault

Java concurrency
Java concurrencyJava concurrency
Java concurrencyfbenault
 
Assertj-DB
Assertj-DBAssertj-DB
Assertj-DBfbenault
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language Rfbenault
 
System rules
System rulesSystem rules
System rulesfbenault
 
Db in-memory
Db in-memoryDb in-memory
Db in-memoryfbenault
 

More from fbenault (12)

Bdd java
Bdd javaBdd java
Bdd java
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Test ng
Test ngTest ng
Test ng
 
Assertj-DB
Assertj-DBAssertj-DB
Assertj-DB
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language R
 
Junit
JunitJunit
Junit
 
System rules
System rulesSystem rules
System rules
 
Db in-memory
Db in-memoryDb in-memory
Db in-memory
 
DbSetup
DbSetupDbSetup
DbSetup
 
Guava
GuavaGuava
Guava
 
Java8
Java8Java8
Java8
 
Easymock
EasymockEasymock
Easymock
 

Recently uploaded

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Recently uploaded (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Property based-testing

  • 1. Property-based testing with Java By Franck Benault Created 06/07/2016 Last update 10/08/2016
  • 2. Property-based testing introduction ● Tests = often (or should be) only one example – We can say « Example-based testing » @Test TestFoo() { //no parameters //my code of test Int x =1 ; Int res =foo(x) ; Assert(..) } ● Yes but if my test is ok for x=1, is it ok for x=25 ?
  • 3. Property-based testing introduction ● Property based testing is – Based on existing check – Randomly generate a lot of input parameter ● Which satisfy predefined properties @Test TestFoo2(String s1, int x ) { //parameters ! //my code of test int res =foo(x) ; //the parameter are used in the test Assert(..) }
  • 5. Property-based testing introduction ● Property based testing functionalities – Tests with parameters ● Values of parameters (randonly or following an order) generated – N times ● Values of parameters satisfying properties – >0, <0 – Filter of the bad values (« assume ») ● Seed value – Value that allow us to relaunch the tests with the same random values ● Shrinking – If the test fails, the framework tries to find the lowest values which fail the test
  • 6. Property-based testing links ● My examples in Github – https://github.com/franck-benault/property-based-testing ● Other links – http://www.ontestautomation.com/an-introduction-to-property ● Good introduction
  • 7. Seed and Shrinking ● Shrinking – If the test fails, repeat the test until it finds the simpliest test case that still fails ● Seed – There is a random generation – But the seed value allows us to reproduce the exact same run – The seed value is the only source of randomness
  • 8. Goal of this presentation ● Goal (in java world) – Limitation of the classical test – Simple presentation of property based testing – First Comparison of the main tools – Notion of seed and shrinking
  • 9. Remind over Assume in JUnit ● Assume = assumption – Ignore if it fails – In method @BeforeClass, @Before, @Test – Possible assumption ● AssumeTrue ● AssumeEquals, AssumeSame ● AssumeNull, AssumeNotNull ● AssumeThat (matcher)
  • 10. Annotation @Theory of JUnit ● Annotation @Theory – since Junit 4.4 – Junit only (not testNG) – Specific Runner (class Theories) ● But all the junit functionalities are honored – @Test, @Before, @After, @BeforeClass, @AfterClass ● Two parts – Data creation – Theory (test with parameters and @Theory)
  • 11. Annotation @Theory of JUnit ● Data creation – Annotations ● Datapoint (on value) ● Datapoints (on tabs public static method or variable) ● FromDataPoints annotation ● TestedOn (on parameters type int) ● It is possible to write your own annotations ● Theory (test with parameters and @Theory) – Parameter nullsAccepted
  • 12. Annotation @Theory of JUnit ● Limitation – Experimental package – No advanced data generation ● No random values – No seed, no shrinking – Known bug with enumerations
  • 13. Junit-Quickcheck ● Junit-Quickcheck – Property based testing for Java – Runner = JUnitQuickcheck – Random data generated – Test annotated with @Property ● Variable trials (number of tests default = 100) – Seed and Shrinking
  • 14. Junit-Quickcheck ● Basic type supported random generation – Primitives (int, boolean ...) – String ... ● Annotation ValuesOf – Enum, boolean (no random generation, sequential generation) ● Annotation @InRange (min , max) – integer ● Possible to write our own generator – @From(XXX.class) ● where XXX is an extension of Generator
  • 15. Junit-Quickcheck ● Limitations – java8 only – Junit only (not testNG) – Shrinking is not working well
  • 16. Quicktheory ● Quickcheck – Junit or TestNG – The loop is inside the test (default loop of 1000 times) ● qt.forAll(...) ● Random generation (with seed option) – Assumption using assuming method ● The loop size is still 1000 – Seed and shrinking working fine
  • 17. Quicktheory generator and source ● Integer / long generation – All, AllPositive (for integer only), between – More possibilities using assuming ● Float / Double – All, from 0 to 1, positive, negative ● Boolean – All ● You can define your own source and generator
  • 18. Quicktheory ● Limitations – Less integrated in the test framework – java8 only – Lack of documentation
  • 19. Conclusion ● Useful for the robustness tests ?