Generator-based Testing: A State By State Approach

Transcription

Generator-based Testing:A State by State ApproachChris StrublePNSQC 2020#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here1CompanyChrisOr PersonalStrubleLogo/NameMCCHere

About me Chris StrubleSenior Software Development Engineer in Test (SDET)Over 25 years in software industryJoined Meteorcomm (MCC) in 2019Currently focused on functional test automationI live in Renton, Washington with my wife, daughter and two catsI play guitar and computer strategy games, and write music andfantasy fiction#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here2CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Key points What is Example-based testing (EBT)?What is Generator-based testing (GBT)? How is it differentfrom EBT? Why use it?What are three examples of GBT practices? How are theydifferent? What are the advantages of each?How can I master GBT and apply it in my career?#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here3CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Evolution of Software TestingTest DesignTest zed #hashtagsGenerator-basedTesting here4CompanyChrisOr PersonalStrubleLogo/NameMCCHere

A manually designed test case Given I have a locomotive travelling at 80-mph When it approaches a curve with a 30-mph speed limit Then an overspeed warning message should be sent to the operatorconsole And the operator does not slow the train within 30 seconds And I should see the locomotive slow safely to a stop automatically that uses a concrete scenario #PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here5CompanyChrisOr PersonalStrubleLogo/NameMCCHere

to suggest a general claim is Given I have a locomotive travelling at some speed When it approaches a curve with a lower speed limit Then an overspeed warning message should be sent to the operatorconsole And the operator does not slow the train in time And I should see the locomotive slow safely to a stop automatically an “example-based test case”.#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here6CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Example-based testing (EBT)Any software testing practice where: Test cases are manually designed one example at a time With the goal of suggesting that the software works By demonstrating automatically that each example works#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here7CompanyChrisOr PersonalStrubleLogo/NameMCCHere

EBT practices and #PNSQC2020MochaBDDTDDBehavePaperTitle/personalized #hashtagsGenerator-basedTesting here8CompanyChrisOr PersonalStrubleLogo/NameMCCHere

EBT is good. But Limitation It takes MANY concrete examples for people to beconfident about a general claim People are not good at thinking of many examplesConsequence Defects escape Lack of imagination (“no one thought of that”)#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here9CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Generator-based testing (GBT)Any software testing practice where: Test cases are generated automatically from a description of behavior With the goal of discovering defects in the software By demonstrating automatically if each generated test case worksWhat if software could “think of” more examples?#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here10CompanyChrisOr PersonalStrubleLogo/NameMCCHere

kCheckMBT GraphWalkerGramTestFuzzingGBT practices and toolsPeach FuzzerPaperTitle/personalized #hashtagsGenerator-basedTesting here11CompanyChrisOr PersonalStrubleLogo/NameMCCHere

GBT processTesterDescriptionGeneratorTest CaseExecutorOracleFailureRepro Case#PNSQC2020ShrinkerPaperTitle/personalized #hashtagsGenerator-basedTesting hereRepeater12CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Three GBT practices Model-based Testing (MBT)FuzzingProperty-based Testing (PBT)Each has been used for at least 20 yearsEach has found major escaped defects#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here13CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Model-based testing (MBT) Description is a directed graph of the possible softwarebehaviors State machine Process flow diagram Generator uses a search algorithm to traverse graphUsed since late 1990s Protocols, UI, workflows, ISTQB Model-based Tester Certification – since 2015“Automate your brain, not just your hands.” - Harry Robinson#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here14CompanyChrisOr PersonalStrubleLogo/NameMCCHere

My MBT Journey – 2000 - 2020 In 2000 I used the TestMaster MBTtool to generate tests for HP printerdriver installer In six months I found over 100 defectsIn 2008 I released Hanno MBT toolfor web application testing in Java In 2012 I used Microsoft SpecExplorer MBT tool to test a .NETweb application #PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here15CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Mars Polar Lander Crash - 1999 Probe crashed during landing NASA suspected a software defect Team used T-VEC MBT tool to modeland generate tests for the TouchdownMonitor system Detected the fault in a few weeks Engines shut down 40 meters above thesurfaceMBT #PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here16CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Fuzzing (Fuzz Testing) Description of interface onlyGenerator (fuzzer) createsrandom or malformed input datauntil a crash or exception occursShrinks automatically on failureUsed since 1990 Parsers, grammars Web security testing User input devices#PNSQC2020Fuzz (v): to envelop in a hazePaperTitle/personalized #hashtagsGenerator-basedTesting here17CompanyChrisOr PersonalStrubleLogo/NameMCCHere

HeartBleed Vulnerability - 2014 OpenSSL vulnerability since 2012Possible to penetrate computersystems without leaving a traceDiscovered in April 2014 Neel Mehta of Google, using codeinspection Synopsis team in Finland, usingDefensics fuzzing tool Still unpatched systems todayFuzzing #PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here18CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Property-based Testing (PBT)Description is a “property” or“general claim”, written in code Generator uses random input datauntil it finds a falsifying example Shrinks automatically on test failure John Hughes creates QuickCheck in1999 from hypothesis import givenfrom hypothesis.strategies import text@given(text())def test decode inverts encode(s):assert decode(encode(s)) s Haskell - 35 languages David MacIver creates Hypothesis in “Don’t write tests. Generate them!”2015- John Hughes Python - Java, Ruby#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here19CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Volvo Emergency Braking - 2015Volvo hired John Hughes’ company(Quviq) to test the AutoSARembedded system in its vehicles The Quviq team in Sweden used theQuickCheck PBT tool to defineproperties and generate tests Found over 200 new defects Fault allowed emergency brakingsystem to be given a lower prioritythan adjusting the volumePBT #PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here20CompanyChrisOr PersonalStrubleLogo/NameMCCHere

GBT is not widely adoptedSearch TermLinkedIn Worldwide Job ResultsSoftware test quality15513Software test quality “automated”5669Software test quality “TDD”823Software test quality “BDD”622Software test quality “ATDD”72Software test quality “MBT”3Software test quality “Fuzz”2Software test quality “PBT”0#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here21CompanyChrisOr PersonalStrubleLogo/NameMCCHere

About Meteorcomm Telecommunications companybased in Renton, WashingtonDevelops Interoperable TrainControl Messaging (ITCM), amessaging system for railroadsPositive Train Control (PTC), asafety system mandated bythe Rail Safety ImprovementAct of 2008#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here22CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Introducing MBT at Meteorcomm In July 2019 I decided to introduce MBT at MeteorcommI wanted to finish in a two-week “innovation sprint”I wanted to use Ruby because we use it for our EBT testsI used GraphWalker, an open source MBT tool written inJava, with a REST APII wrote Test Generator, a Ruby program that usesGraphWalker to generate and execute Ruby test code#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here23CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Demos Test Generator – Ruby MBT tool I wrote Show an example model for an ITCM test component Generate, run and rerun a functional test case Rantly – open source PBT tool for Ruby Start with EBT RSpec unit tests Create a PBT unit test, generate, fail, shrink#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here24CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Getting Started with GBT Start with your existing EBT functional test casesCreate a script to run them in random orderYour EBT tests will be more reliableIncrease your comfort level with randomness“Can you let randomness into your life?” – TJ Usiyan,Property-Based Testing with SwiftCheck#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here25CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Contact MeLinkedIn https://www.linkedin.com/in/chrisstruble/Blog https://chrisstrublewrites.blogspot.comEmail alized #hashtagsGenerator-basedTesting here26CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Questions?#PNSQC2020PaperTitle/personalized #hashtagsGenerator-basedTesting here27CompanyChrisOr PersonalStrubleLogo/NameMCCHere

Conformiq GraphWalker. QuickCheck Defensics Hypothesis GramTest. T-VEC. Peach Fuzzer. #PNSQC2020 Paper Title/personalized # hashtags here Company Or Personal Logo/Name 12 Here GBT process. Generator-based Testing. Chris . Struble. MCC. Failure Tester Description Generator Test Case Executor Oracle