SlideShare a Scribd company logo
Making property-based testing
easier to read for humans
Laura M. Castro
February 18th, 2016
Stakeholder involvement & software testing
The challenge of communication
Active stakeholder participation is an agile best practice1
Early testing is also an agile best practice1
1
Agile practices are considered mainstream, with adoption rates ≈50%2 of 30
Stakeholder involvement & software testing
The challenge of communication
Active stakeholder participation is an agile best practice1
stakeholder involvement requires inclusive modeling
(UML activity diagrams, user stories)
Early testing is also an agile best practice1
best represented by Test-Driven Development (TDD)
1
Agile practices are considered mainstream, with adoption rates ≈50%2 of 30
Stakeholder involvement & software testing
The challenge of communication
Active stakeholder participation is an agile best practice1
stakeholder involvement requires inclusive modeling
(UML activity diagrams, user stories)
Early testing is also an agile best practice1
best represented by Test-Driven Development (TDD)
stakeholder involvement + early testing =
Behaviour-Driven Development (BDD)
1
Agile practices are considered mainstream, with adoption rates ≈50%2 of 30
Behaviour-Driven Development
Feature: Deletion of element from list
In order to operate lists
As a user of the lists module
I want to delete an element from a list
Scenario: Delete integer from list of integers
Given I have the integer 3
And I have the list of integers [0,8,6]
When I use the function lists:delete/2
Then the resulting list should not contain 3
3 of 30
Behaviour-Driven Development
The behaviour becomes test case
given("I have the integer (d+)", S, [Num]) ->
{ok, S ++ [list_to_integer(Num)]};
...
when("I use the function (w+) from the module (w+)", S, [F, M]) ->
{ok, apply(list_to_atom(M), list_to_atom(F), S)}.
then("the resulting list should not contain (d+)", S, [Num]) ->
case not lists:member(list_to_integer(Num), S) of
true -> {ok, S};
false -> {failed, S}
end.
4 of 30
Behaviour-Driven Development
Is this catching on?
5 of 30
Behaviour-Driven Development
Is this catching on?
6 of 30
Behaviour-Driven Development
Pros and cons
Good as communication tool
a number of implementations in many languages:
C++, Clojure, Erlang, Java, JavaScript, Lua, .NET, PHP,…
Not as good as testing tool
run as many test cases as you can write
well-known problems of “traditional” testing:
specification, implementation, maintainability, effectiveness
7 of 30
Property-Based Testing (PBT)
Strategy for improved testing: abstraction + automation
write properties instead of test cases
properties are used to automatically
generate, run, and diagnose many, many test cases
8 of 30
Property-Based Testing
A very simple example
How do you write properties? Let’s start simple:
Example: delete an element from a list
9 of 30
Property-Based Testing
A very simple example
How do you write properties? Let’s start simple:
Example: delete an element from a list
Desired functionality?
If I delete an element from a list,
it shouldn't be there anymore.
9 of 30
Property-Based Testing
A very simple example
How do you write properties? Let’s start simple:
Example: delete an element from a list
Desired functionality?
If I delete an element from a list,
it shouldn't be there anymore.
Which item? Which list? Any.
9 of 30
Property-Based Testing
A very simple example
prop_simple() ->
?FORALL(I, item(),
?FORALL(L, list(item()),
not lists:member(I, lists:delete(I, L)))).
10 of 30
Property-Based Testing
A very simple example
prop_simple() ->
?FORALL(I, item(),
?FORALL(L, list(item()),
not lists:member(I, lists:delete(I, L)))).
11 of 30
Property-Based Testing
A very simple example
prop_simple() ->
?FORALL(I, item(),
?FORALL(L, list(item()),
not lists:member(I, lists:delete(I, L)))).
12 of 30
Property-Based Testing
A very simple example
prop_simple() ->
?FORALL(I, item(),
?FORALL(L, list(item()),
[] == [ X || X <- lists:delete(I, L), X == I])).
13 of 30
Property-Based Testing
A very simple example
prop_simple() ->
?FORALL(I, item(),
?FORALL(L, list(item()),
not lists:member(I, lists:delete(I, L)))).
14 of 30
Property-Based Testing
A very simple example
> eqc:quickcheck(simple_eqc:prop_simple()).
................................................
................................................
....
OK, passed 100 tests
15 of 30
Property-Based Testing
A very simple example
> eqc:quickcheck(simple_eqc:prop_simple()).
................................................
.................... Failed! After 69 tests.
15
[-13,-15,-2,-17,-20,15,15]
Shrinking xxxxxxxx.xx.xxxxxxxx (2 times)
15
[15,15]
16 of 30
Property-Based Testing
A more complex example
How complex can it get? Models for stateful components.
Example: EVM registry
register(Name, Pid) -> ok
unregister(Name) -> ok
whereis(Name) -> Pid | undefined
17 of 30
Property-Based Testing
A more complex example
How complex can it get? Models for stateful components.
Example: EVM registry
register(Name, Pid) -> ok
unregister(Name) -> ok
whereis(Name) -> Pid | undefined
Desired functionality?
If I perform a sequence of registry actions,
I expect compliance with model at all times.
17 of 30
Property-Based Testing
A more complex example
How complex can it get? Models for stateful components.
Example: EVM registry
register(Name, Pid) -> ok
unregister(Name) -> ok
whereis(Name) -> Pid | undefined
Desired functionality?
If I perform a sequence of registry actions,
I expect compliance with model at all times.
Which sequences of actions? Any.
17 of 30
Property-Based Testing
A more complex example
prop_registry() ->
?FORALL(Cmds, commands(registry_model),
begin
... % setup code
{H, S, TResult} = run_commands(registry_model,Cmds),
... % cleanup code
TResult == ok
end).
18 of 30
Property-Based Testing
A more complex example
prop_registry() ->
?FORALL(Cmds, commands(registry_model),
begin
... % setup code
{H, S, TResult} = run_commands(registry_model,Cmds),
... % cleanup code
TResult == ok
end).
19 of 30
Property-Based Testing
A more complex example
register_pre(S) ->
S#state.pids /= [].
...
unregister_next(S,_,[Name]) ->
S#state{regs = lists:keydelete(Name,1,S#state.regs)}.
...
whereis_post(S, [Name], Result) ->
case lists:keyfind(Name, 1, S#state.regs) of
{Name,Value} -> Res =:= Value;
false -> Res =:= undefined
end.
20 of 30
Property-Based Testing
Pros and cons
Good as testing tool
run as many test cases as you have time to execute
run different test cases every time
get reduced counterexamples, for focused debugging
get a functional specification of the software
a number of implementations in many languages:
Clojure, Lisp, Erlang, ML, Prolog, Scala, Scheme, Smalltalk,…
Not as good as communication tool
21 of 30
readSpec
making PBT easier to read for humans
Get (semi)natural language descriptions
for sample test cases that test properties produce
1. Write PBT artifacts (properties, models)
2. Get readSpec to translate them into cucumber-like features
implemented in Erlang
uses Quviq QuickCheck’s coverage-based suite generation
Available at:
https://github.com/prowessproject/readspec
22 of 30
readSpec
A very simple example: what do you get?
File: simple.feature
FEATURE: simple
Simple QuickCheck properties
...
SCENARIO: Deleting an integer from a list should
result in a list that does not contain that integer.
GIVEN I have the integer 6
AND I have the list [-1, 2, 13, 0, 5]
THEN IS FALSE THAT the integer 6 is in
the result of calling lists:delete/2
with 6 and [-1, 2, 13, 0, 5].
...
23 of 30
readSpec
A very simple example: what do you get?
File: prop_simple.counterexample.feature
GIVEN I have the integer 15
AND I have the list [15, 15]
THEN the integer 15 is in
the result of calling lists:delete/2 with 15 and [15, 15].
24 of 30
readSpec
A very simple example: what do you get?
**********************************************************
CALL: register/2
**********************************************************
POSSIBILITIES ...
================================
*** REQUIREMENTS ***
[*] The field called "pids" must be equal to the empty list
*** RESULT ***
the literal 'false'
================================
OTHERWISE ...
================================
*** RESULT ***
the literal 'true'
25 of 30
VoDKATV: industrial pilot study
26 of 30
VoDKATV: industrial pilot study
Research questions
RQ 1) Can readSpec produce efficient text representations of
test properties?
RQ 2) Are readSpec text representations an effective way to
communicate among stakeholders?
27 of 30
VoDKATV: industrial pilot study
Measurements
RQ 1) Amount of time to generate the textual representation
RQ 1) LOC of textual representations w.r.t.
LOC of corresponding test properties/models
RQ 2) Stakeholders average rating of usefulness
(would use them instead of current way of communic.?)
RQ 2) Stakeholders average rating of usability
(appropriate? easy to understand/follow?)
28 of 30
VoDKATV: industrial pilot study
Results
Amount of time needed in the order of milliseconds
Nature of output (verbosity, number of lines) appropriate
Simple cases: high degree of influence of personal skills and
background on deeming text more helpful than property code
Complex cases: some people still cannot make sense of
either; the rest consistently agree the text is more helpful
enough to provide the insights needed to suggest more tests!
29 of 30
readSpec: making PBT easier to read for humans
Final quotes
“readSpec looks human-friendly”
“simple cases are too verbose for tech people (code is shorter)”
“helps in understanding tests better, especially when they’re complex”
“it’s interesting when cases reach certain complexity”
“presents requirements in an explicit way, that can slip your mind o/w”
“this is very helpful for people who are not familiar with the code”
“only with a good level of maturity and experience one could be more
comfortable with QC properties and models”
30 of 30

More Related Content

PPTX
Towards Automated Supports for Code Reviews using Reviewer Recommendation and...
PDF
Finding latent code errors via machine learning over program ...
PPTX
PDF
Test design techniques
PPTX
Sta unit 4(abimanyu)
PPTX
A software fault localization technique based on program mutations
PPTX
Feature Selection Techniques for Software Fault Prediction (Summary)
Towards Automated Supports for Code Reviews using Reviewer Recommendation and...
Finding latent code errors via machine learning over program ...
Test design techniques
Sta unit 4(abimanyu)
A software fault localization technique based on program mutations
Feature Selection Techniques for Software Fault Prediction (Summary)

What's hot (20)

PDF
A Natural Language Programming Approach for Requirements-based Security Testing
PPTX
10 software testing_technique
PDF
Automated and Scalable Solutions for Software Testing: The Essential Role of ...
PDF
findbugs Bernhard Merkle
PPTX
Sta unit 3(abimanyu)
PDF
SAIConference_PAPER
PDF
An Approach to Software Testing of Machine Learning Applications
PDF
SBST 2019 Keynote
PDF
Transferring Software Testing Tools to Practice (AST 2017 Keynote)
PDF
Mutation Analysis and Testing for Cyber-Physical Systems: Scalable Solutions...
PDF
Code coverage based test case selection and prioritization
PPTX
Black Box Testing
PPTX
Sta unit 2(abimanyu)
PPTX
Finding bugs that matter with Findbugs
PDF
Diversity Maximization Speedup for Fault Localization
PDF
Istqb ctfl-series - Black Box Testing
PPTX
Amin Milani Fard: Directed Model Inference for Testing and Analysis of Web Ap...
PPT
Software Testing Techniques
PPTX
Advances in Unit Testing: Theory and Practice
A Natural Language Programming Approach for Requirements-based Security Testing
10 software testing_technique
Automated and Scalable Solutions for Software Testing: The Essential Role of ...
findbugs Bernhard Merkle
Sta unit 3(abimanyu)
SAIConference_PAPER
An Approach to Software Testing of Machine Learning Applications
SBST 2019 Keynote
Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Mutation Analysis and Testing for Cyber-Physical Systems: Scalable Solutions...
Code coverage based test case selection and prioritization
Black Box Testing
Sta unit 2(abimanyu)
Finding bugs that matter with Findbugs
Diversity Maximization Speedup for Fault Localization
Istqb ctfl-series - Black Box Testing
Amin Milani Fard: Directed Model Inference for Testing and Analysis of Web Ap...
Software Testing Techniques
Advances in Unit Testing: Theory and Practice
Ad

Viewers also liked (11)

DOC
Pino coviello, rodriguez
PPTX
Property Based Testing
PDF
Property-based testing
PDF
Property-based testing
PDF
ScalaCheckでProperty-based Testing
PDF
Property-Based Testing for Services
PDF
Property based testing - Less is more
PDF
Better Tests, Less Code: Property-based Testing
PDF
Property based Testing - generative data & executable domain rules
PDF
An introduction to property based testing
PPTX
UNIT TESTING PPT
Pino coviello, rodriguez
Property Based Testing
Property-based testing
Property-based testing
ScalaCheckでProperty-based Testing
Property-Based Testing for Services
Property based testing - Less is more
Better Tests, Less Code: Property-based Testing
Property based Testing - generative data & executable domain rules
An introduction to property based testing
UNIT TESTING PPT
Ad

Similar to Making property-based testing easier to read for humans (20)

DOCX
Chapter 10 Testing and Quality Assurance1Unders.docx
PPTX
Automation Testing theory notes.pptx
PDF
Anders Claesson - Test Strategies in Agile Projects - EuroSTAR 2010
PPTX
Test Driven Development - The art of fearless programming
ODP
Effective unit testing
PPT
Role+Of+Testing+In+Sdlc
PDF
Programming with GUTs
PPTX
Siguccs20101026
PPT
B2 2005 introduction_load_testing_blackboard_primer_draft
ODP
Introduction to programming with python
PPT
Xp Day 080506 Unit Tests And Mocks
PPT
XP through TDD
PPT
Software development effort reduction with Co-op
PPT
Use Case Workshop
PDF
OORPT Dynamic Analysis
PPTX
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
PPT
CS2006Ch02A.ppt dfxgbfdcgbhfcdhbfdcbfdcgfdg
DOCX
DOCX
PPTX
Networking chapter jkl; dfghyubLec 1.pptx
Chapter 10 Testing and Quality Assurance1Unders.docx
Automation Testing theory notes.pptx
Anders Claesson - Test Strategies in Agile Projects - EuroSTAR 2010
Test Driven Development - The art of fearless programming
Effective unit testing
Role+Of+Testing+In+Sdlc
Programming with GUTs
Siguccs20101026
B2 2005 introduction_load_testing_blackboard_primer_draft
Introduction to programming with python
Xp Day 080506 Unit Tests And Mocks
XP through TDD
Software development effort reduction with Co-op
Use Case Workshop
OORPT Dynamic Analysis
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
CS2006Ch02A.ppt dfxgbfdcgbhfcdhbfdcbfdcgfdg
Networking chapter jkl; dfghyubLec 1.pptx

More from Laura M. Castro (20)

PDF
12 years supporting Software Architecture teaching with BEAMs
PDF
Ola, ChatGPT: que podo facer hoxe? Exploración dos nesgos de xénero na IA Xer...
PDF
O software libre como vehículo de introdución á perspectiva de xénero
PDF
Teaching the next generation of Software Architects
PDF
Atención a la diversidad de estilos de aprendizaje: experiencia en la docenci...
PDF
Das risas enlatadas ás risas sintéticas: explorando o humor das IAs xerativas
PDF
Que é o que fai a investigación en sistemas distribuídos? (Programa STEMBach)
PDF
De Elviña... até a NASA! (Día Internacional da Muller e a Nena na Ciencia)
PDF
El futuro de la tecnología: ¿cómo imaginas la tecnología del futuro?
PDF
Effective Teaching Strategies for Large Classes: A Case Study in Software Arc...
PDF
Muller e tecnoloxía: participación + visibilidade = empoderamento
PDF
Obstáculos invisíbeis na implantación de software: Unha historia libre basead...
PDF
Sesgos de género en ChatGPT e Inteligencias Artificiales
PDF
Violência online em redes sociais: a tecnologia Elixir na pesquisa
PDF
Ya he usado Erlang, y ahora… ¿es mi arquitectura tan buena como creo?
PDF
Targeting Property-Based Testing inside out
PDF
Ola, ChatGPT... que carreira sería boa para min?
PDF
IAs xerativas e nesgos de xénero
PDF
As intelixencias artificiais como xeradoras de cultura: exploración dos nesgo...
PDF
David vs. Goliat: lecciones aprendidas de una experiencia fallida de adopción...
12 years supporting Software Architecture teaching with BEAMs
Ola, ChatGPT: que podo facer hoxe? Exploración dos nesgos de xénero na IA Xer...
O software libre como vehículo de introdución á perspectiva de xénero
Teaching the next generation of Software Architects
Atención a la diversidad de estilos de aprendizaje: experiencia en la docenci...
Das risas enlatadas ás risas sintéticas: explorando o humor das IAs xerativas
Que é o que fai a investigación en sistemas distribuídos? (Programa STEMBach)
De Elviña... até a NASA! (Día Internacional da Muller e a Nena na Ciencia)
El futuro de la tecnología: ¿cómo imaginas la tecnología del futuro?
Effective Teaching Strategies for Large Classes: A Case Study in Software Arc...
Muller e tecnoloxía: participación + visibilidade = empoderamento
Obstáculos invisíbeis na implantación de software: Unha historia libre basead...
Sesgos de género en ChatGPT e Inteligencias Artificiales
Violência online em redes sociais: a tecnologia Elixir na pesquisa
Ya he usado Erlang, y ahora… ¿es mi arquitectura tan buena como creo?
Targeting Property-Based Testing inside out
Ola, ChatGPT... que carreira sería boa para min?
IAs xerativas e nesgos de xénero
As intelixencias artificiais como xeradoras de cultura: exploración dos nesgo...
David vs. Goliat: lecciones aprendidas de una experiencia fallida de adopción...

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Machine Learning_overview_presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Big Data Technologies - Introduction.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Assigned Numbers - 2025 - Bluetooth® Document
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Machine Learning_overview_presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
MYSQL Presentation for SQL database connectivity
Review of recent advances in non-invasive hemoglobin estimation
Big Data Technologies - Introduction.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf

Making property-based testing easier to read for humans

  • 1. Making property-based testing easier to read for humans Laura M. Castro February 18th, 2016
  • 2. Stakeholder involvement & software testing The challenge of communication Active stakeholder participation is an agile best practice1 Early testing is also an agile best practice1 1 Agile practices are considered mainstream, with adoption rates ≈50%2 of 30
  • 3. Stakeholder involvement & software testing The challenge of communication Active stakeholder participation is an agile best practice1 stakeholder involvement requires inclusive modeling (UML activity diagrams, user stories) Early testing is also an agile best practice1 best represented by Test-Driven Development (TDD) 1 Agile practices are considered mainstream, with adoption rates ≈50%2 of 30
  • 4. Stakeholder involvement & software testing The challenge of communication Active stakeholder participation is an agile best practice1 stakeholder involvement requires inclusive modeling (UML activity diagrams, user stories) Early testing is also an agile best practice1 best represented by Test-Driven Development (TDD) stakeholder involvement + early testing = Behaviour-Driven Development (BDD) 1 Agile practices are considered mainstream, with adoption rates ≈50%2 of 30
  • 5. Behaviour-Driven Development Feature: Deletion of element from list In order to operate lists As a user of the lists module I want to delete an element from a list Scenario: Delete integer from list of integers Given I have the integer 3 And I have the list of integers [0,8,6] When I use the function lists:delete/2 Then the resulting list should not contain 3 3 of 30
  • 6. Behaviour-Driven Development The behaviour becomes test case given("I have the integer (d+)", S, [Num]) -> {ok, S ++ [list_to_integer(Num)]}; ... when("I use the function (w+) from the module (w+)", S, [F, M]) -> {ok, apply(list_to_atom(M), list_to_atom(F), S)}. then("the resulting list should not contain (d+)", S, [Num]) -> case not lists:member(list_to_integer(Num), S) of true -> {ok, S}; false -> {failed, S} end. 4 of 30
  • 9. Behaviour-Driven Development Pros and cons Good as communication tool a number of implementations in many languages: C++, Clojure, Erlang, Java, JavaScript, Lua, .NET, PHP,… Not as good as testing tool run as many test cases as you can write well-known problems of “traditional” testing: specification, implementation, maintainability, effectiveness 7 of 30
  • 10. Property-Based Testing (PBT) Strategy for improved testing: abstraction + automation write properties instead of test cases properties are used to automatically generate, run, and diagnose many, many test cases 8 of 30
  • 11. Property-Based Testing A very simple example How do you write properties? Let’s start simple: Example: delete an element from a list 9 of 30
  • 12. Property-Based Testing A very simple example How do you write properties? Let’s start simple: Example: delete an element from a list Desired functionality? If I delete an element from a list, it shouldn't be there anymore. 9 of 30
  • 13. Property-Based Testing A very simple example How do you write properties? Let’s start simple: Example: delete an element from a list Desired functionality? If I delete an element from a list, it shouldn't be there anymore. Which item? Which list? Any. 9 of 30
  • 14. Property-Based Testing A very simple example prop_simple() -> ?FORALL(I, item(), ?FORALL(L, list(item()), not lists:member(I, lists:delete(I, L)))). 10 of 30
  • 15. Property-Based Testing A very simple example prop_simple() -> ?FORALL(I, item(), ?FORALL(L, list(item()), not lists:member(I, lists:delete(I, L)))). 11 of 30
  • 16. Property-Based Testing A very simple example prop_simple() -> ?FORALL(I, item(), ?FORALL(L, list(item()), not lists:member(I, lists:delete(I, L)))). 12 of 30
  • 17. Property-Based Testing A very simple example prop_simple() -> ?FORALL(I, item(), ?FORALL(L, list(item()), [] == [ X || X <- lists:delete(I, L), X == I])). 13 of 30
  • 18. Property-Based Testing A very simple example prop_simple() -> ?FORALL(I, item(), ?FORALL(L, list(item()), not lists:member(I, lists:delete(I, L)))). 14 of 30
  • 19. Property-Based Testing A very simple example > eqc:quickcheck(simple_eqc:prop_simple()). ................................................ ................................................ .... OK, passed 100 tests 15 of 30
  • 20. Property-Based Testing A very simple example > eqc:quickcheck(simple_eqc:prop_simple()). ................................................ .................... Failed! After 69 tests. 15 [-13,-15,-2,-17,-20,15,15] Shrinking xxxxxxxx.xx.xxxxxxxx (2 times) 15 [15,15] 16 of 30
  • 21. Property-Based Testing A more complex example How complex can it get? Models for stateful components. Example: EVM registry register(Name, Pid) -> ok unregister(Name) -> ok whereis(Name) -> Pid | undefined 17 of 30
  • 22. Property-Based Testing A more complex example How complex can it get? Models for stateful components. Example: EVM registry register(Name, Pid) -> ok unregister(Name) -> ok whereis(Name) -> Pid | undefined Desired functionality? If I perform a sequence of registry actions, I expect compliance with model at all times. 17 of 30
  • 23. Property-Based Testing A more complex example How complex can it get? Models for stateful components. Example: EVM registry register(Name, Pid) -> ok unregister(Name) -> ok whereis(Name) -> Pid | undefined Desired functionality? If I perform a sequence of registry actions, I expect compliance with model at all times. Which sequences of actions? Any. 17 of 30
  • 24. Property-Based Testing A more complex example prop_registry() -> ?FORALL(Cmds, commands(registry_model), begin ... % setup code {H, S, TResult} = run_commands(registry_model,Cmds), ... % cleanup code TResult == ok end). 18 of 30
  • 25. Property-Based Testing A more complex example prop_registry() -> ?FORALL(Cmds, commands(registry_model), begin ... % setup code {H, S, TResult} = run_commands(registry_model,Cmds), ... % cleanup code TResult == ok end). 19 of 30
  • 26. Property-Based Testing A more complex example register_pre(S) -> S#state.pids /= []. ... unregister_next(S,_,[Name]) -> S#state{regs = lists:keydelete(Name,1,S#state.regs)}. ... whereis_post(S, [Name], Result) -> case lists:keyfind(Name, 1, S#state.regs) of {Name,Value} -> Res =:= Value; false -> Res =:= undefined end. 20 of 30
  • 27. Property-Based Testing Pros and cons Good as testing tool run as many test cases as you have time to execute run different test cases every time get reduced counterexamples, for focused debugging get a functional specification of the software a number of implementations in many languages: Clojure, Lisp, Erlang, ML, Prolog, Scala, Scheme, Smalltalk,… Not as good as communication tool 21 of 30
  • 28. readSpec making PBT easier to read for humans Get (semi)natural language descriptions for sample test cases that test properties produce 1. Write PBT artifacts (properties, models) 2. Get readSpec to translate them into cucumber-like features implemented in Erlang uses Quviq QuickCheck’s coverage-based suite generation Available at: https://github.com/prowessproject/readspec 22 of 30
  • 29. readSpec A very simple example: what do you get? File: simple.feature FEATURE: simple Simple QuickCheck properties ... SCENARIO: Deleting an integer from a list should result in a list that does not contain that integer. GIVEN I have the integer 6 AND I have the list [-1, 2, 13, 0, 5] THEN IS FALSE THAT the integer 6 is in the result of calling lists:delete/2 with 6 and [-1, 2, 13, 0, 5]. ... 23 of 30
  • 30. readSpec A very simple example: what do you get? File: prop_simple.counterexample.feature GIVEN I have the integer 15 AND I have the list [15, 15] THEN the integer 15 is in the result of calling lists:delete/2 with 15 and [15, 15]. 24 of 30
  • 31. readSpec A very simple example: what do you get? ********************************************************** CALL: register/2 ********************************************************** POSSIBILITIES ... ================================ *** REQUIREMENTS *** [*] The field called "pids" must be equal to the empty list *** RESULT *** the literal 'false' ================================ OTHERWISE ... ================================ *** RESULT *** the literal 'true' 25 of 30
  • 32. VoDKATV: industrial pilot study 26 of 30
  • 33. VoDKATV: industrial pilot study Research questions RQ 1) Can readSpec produce efficient text representations of test properties? RQ 2) Are readSpec text representations an effective way to communicate among stakeholders? 27 of 30
  • 34. VoDKATV: industrial pilot study Measurements RQ 1) Amount of time to generate the textual representation RQ 1) LOC of textual representations w.r.t. LOC of corresponding test properties/models RQ 2) Stakeholders average rating of usefulness (would use them instead of current way of communic.?) RQ 2) Stakeholders average rating of usability (appropriate? easy to understand/follow?) 28 of 30
  • 35. VoDKATV: industrial pilot study Results Amount of time needed in the order of milliseconds Nature of output (verbosity, number of lines) appropriate Simple cases: high degree of influence of personal skills and background on deeming text more helpful than property code Complex cases: some people still cannot make sense of either; the rest consistently agree the text is more helpful enough to provide the insights needed to suggest more tests! 29 of 30
  • 36. readSpec: making PBT easier to read for humans Final quotes “readSpec looks human-friendly” “simple cases are too verbose for tech people (code is shorter)” “helps in understanding tests better, especially when they’re complex” “it’s interesting when cases reach certain complexity” “presents requirements in an explicit way, that can slip your mind o/w” “this is very helpful for people who are not familiar with the code” “only with a good level of maturity and experience one could be more comfortable with QC properties and models” 30 of 30