search based software engineers need tools
play

Search-Based Software Engineers Need Tools Gordon Fraser, - PowerPoint PPT Presentation

Search-Based Software Engineers Need Tools Gordon Fraser, University of Sheffield Gordon Fraser, University of Sheffield, UK Andrea Arcuri, Simula Research Labs, Norway Contents 1. What is Search Based Software Testing? 2. Building an SBST


  1. Search-Based Software Engineers Need Tools Gordon Fraser, University of Sheffield Gordon Fraser, University of Sheffield, UK Andrea Arcuri, Simula Research Labs, Norway

  2. Contents 1. What is Search Based Software Testing? 2. Building an SBST Tool is Easy! 3. The EvoSuite Test Generation Tool 4. Lessons Learned Building an SBST Tool

  3. Source code Tests Automated test generation

  4. Random Test Data Generation Input

  5. Generating vs Checking Conventional Software Testing Research Write a method to construct test cases Search-Based Testing Write a method 
 to determine how good a test case is

  6. Generating vs Checking Conventional Software Testing Research Write a method to construct test cases Search-Based Testing Write a fitness function 
 to determine how good a test case is

  7. Fitness-guided search Fitness Input

  8. Fitness-guided search Fitness Input

  9. Components of an SBST Tool def testMe(x, y): if x == 2 * (y + 1): return True else : return False Search Algorithm Search Operators Representation Fitness Function Instrumentation Test Execution

  10. Components of an SBST Tool Search Algorithm Meta-heuristic algorithm Representation Encoding of the problem solution Search Operators Modifications of encoded solutions Fitness Function Measure how good a candidate solution is Test Execution Execute tests Instrumentation Collect data/traces for fitness calculation during execution

  11. Contents 1. What is Search Based Software Testing? 2. Building an SBST Tool is Easy! 3. The EvoSuite Test Generation Tool 4. Lessons Learned Building an SBST Tool

  12. def testMe(x, y): if x == 2 * (y + 1): return True else : return False

  13. Components of an SBST Tool Search Algorithm Hill-climbing Representation Search Operators Fitness Function Test Execution Instrumentation

  14. (x-1, y+1) (x, y+1) (x+1, y+1) def testMe(x, y): if x == 2 * (y + 1): return True else : (x-1, y) (x, y) (x+1, y) return False (x-1, y-1) (x, y-1) (x+1, y-1)

  15. Components of an SBST Tool Search Algorithm Hill-climbing Representation Tuple (x, y) Search Operators Neighbourhood of (x, y) Fitness Function Test Execution Instrumentation

  16. Hill Climbing 1. Select Random Value

  17. Hill Climbing 2. Explore Neighbourhood

  18. Hill Climbing 3. Choose better neighbour

  19. Hill Climbing 4. Repeat until optimum is found

  20. Components of an SBST Tool Search Algorithm Hill-climbing Representation Tuple (x, y) Search Operators Neighbourhood of (x, y) Fitness Function Test Execution Instrumentation

  21. Input Output SUT

  22. Trace } Output Instrumented Test Data Fitness Input SUT SUT

  23. def testMe(x, y): if x == 2 * (y + 1): return True else : return False

  24. Components of an SBST Tool Search Algorithm Hill-climbing Representation Tuple (x, y) Search Operators Neighbourhood of (x, y) Fitness Function Branch distance Test Execution Call method Instrumentation Global variable

  25. 9 8 7 6 Fitness 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 Input Value

  26. 9 8 7 6 Fitness 5 4 3 2 1 0 -(2 31 ) 2 31 -1 0 Input Value

  27. def testMe(x, y): if x == 2 * y and y > 1: return True else : return False

  28. Branch Distance Expression Distance True Distance False x == y |x - y| 1 x != y 1 |x - y| x > y y - x + 1 x - y x >= y y - x x - y + 1 x < y x - y+ 1 x - y x <= y x - y x - y + 1

  29. def testMe(x, y): if x == 2 * y and y > 1: return True else : return False

  30. def testMe(x, y): if x <= y: if x == y: print ("Some output") if x > 0: if y == 17: # Target Branch return True return False

  31. Entry true x <= y false true def testMe(x, y): x == y if x <= y: false print if x == y: print ("Some output") if x > 0: true x > 0 if y == 17: # Target Branch false true return True y == 17 return False false return False return True Exit

  32. Entry true x <= y Entry false true x == y false print x <= y Exit true false true true x > 0 x > 0 x == y return False false true true true y == 17 print y == 17 false true return True return False return True Exit

  33. Covering a structure TARGET

  34. Fitness evaluation The test data executes the ‘wrong’ path TARGET

  35. Approach Level = 2 minimisation = 1 = 0 TARGET

  36. Putting it all together Fitness = approach Level + normalised branch distance if a >= b true false TARGET MISSED 
 false true if b >= c Approach Level = 2 
 Branch Distance = b - a if c >= d false true TARGET MISSED 
 Approach Level = 1 
 TARGET TARGET Branch Distance = c - b TARGET MISSED 
 Approach Level = 0 
 Branch Distance = d - c normalised branch distance between 0 and 1 
 indicates how close approach level is to being penetrated

  37. 9 8 7 6 Fitness 5 4 3 2 1 0 -(2 31 ) 2 31 -1 0 Input Value

  38. 9 8 7 6 Fitness 5 4 3 2 1 0 -(2 31 ) 0 2 31 -1 Input Value

  39. 9 8 7 6 Fitness 5 4 3 2 1 0 -(2 31 ) 2 31 -1 0 Input Value

  40. Evolutionary Testing Insertion Mutation Fitness Evaluation Test cases Monitoring Execution Crossover End? Selection

  41. Crossover b c b c a d a d 10 10 20 40 10 10 80 80 b c a d b c a d 20 -5 80 80 20 -5 20 40

  42. Mutation b c a d d a d 10 10 20 40 40 20 20

  43. Selection • Selective pressure: 
 The higher, the more likely the fittest are chosen • Stagnation: 
 Selective pressure too small • Premature convergence: 
 Selective pressure too high • Standard algorithms: 
 Rank selection, tournament selection, roulette wheel selection

  44. Contents 1. What is Search Based Software Testing? 2. Building an SBST Tool is Easy! 3. The EvoSuite Test Generation Tool 4. Lessons Learned Building an SBST Tool

  45. @Test public void test() { int x = 2; int y = 2; int result = x + y; assertEquals(4, result); }

  46. @Test public void test() { int var0 = 10 YearMonthDay var1 = new YearMonthDay(var0); TimeOfDay var2 = new TimeOfDay(); DateTime var3 = var1.toDateTime(var2); DateTime var4 = var3.minus(var0); DateTime var5 = var4.plusSeconds(var0); }

  47. Test Suite Generation Initialize Population int var0 = 10 YearMonthDay var1 = new YearMonthDay(var0); TimeOfDay var2 = new TimeOfDay(); DateTime var3 = var1.toDateTime(var2); DateTime var4 = var3.minus(var0); DateTime var5 = var4.plusSeconds(var0); While not Return best done solution Select parents Recombine parents

  48. Test Suite Generation

  49. Crossover

  50. Mutation

  51. Mutation

  52. Fitness public int gcd(int x, int y) { int tmp; while (y != 0) { tmp = x % y; x = y; y = tmp; } return x; }

  53. Components of an SBST Tool Search Algorithm Genetic Algorithm (+Archive, Seeding, Local Search, DSE) Representation Sets of sequences of Java statements Search Operators Standard GA operators implemented for test suites Fitness Function Sum of branch distances (and others) Test Execution Java reflection Instrumentation Java bytecode instrumentation

  54. EvoSuite http://www.evosuite.org/downloads • Jar release - for command line usage • Maven plugin • IntelliJ plugin • Eclipse plugin • Jenkins plugin

  55. Does it work? 0.4 100% 0.3 75% Bugs found Point is: It takes a tool and lots of engineering to do this. 0.2 50% 0.1 25% 0 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% JFreeChart Closure Math Lang Joda Time SF110: 23,886 Classes 
 Defects4J: 357 real bugs 6,628,619 LOC G. Fraser, A. Arcuri. “A Large Scale Evaluation of Automated Shamshiri et al. "Do Automatically Generated Unit Tests Find Real Unit Test Generation with EvoSuite” TOSEM 24(2), 2014. Faults? An Empirical Study of Effectiveness and Challenges” ASE, 2015

  56. Coverage EvoSuite Manual 100 75 50 25 0 Option Rational DocType ArrayIntList

  57. Time Spent on Testing Assisted Manual 26 19.5 13 6.5 0 FilterIterator FixedOrderComparator ListPopulation PredicatedMap

  58. Fault Detection EvoSuite Manual 2 1.5 1 0.5 0 Option Rational DocType ArrayIntList

  59. Faults Prevention Assisted Manual 16 12 8 4 0 FilterIterator FixedOrderComparator ListPopulation PredicatedMap

  60. Method Names @Test(timeout = 4000) public void test3() throws Throwable { StringExample stringExample0 = new StringExample(); boolean boolean0 = stringExample0.foo(""); assertFalse(boolean0); } @Test(timeout = 4000) public void testFooReturningFalse() throws Throwable { StringExample stringExample0 = new StringExample(); boolean boolean0 = stringExample0.foo(""); assertFalse(boolean0); }

  61. Variable Names @Test(timeout = 4000) public void testFooReturningFalse() throws Throwable { StringExample stringExample0 = new StringExample(); boolean boolean0 = stringExample0.foo(""); assertFalse(boolean0); } @Test(timeout = 4000) public void testFooReturningFalse() throws Throwable { StringExample invokesFoo = new StringExample(); boolean resultFromFoo = invokesFoo.foo(""); assertFalse(resultFromFoo); }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend