from structured natural language specifications
play

from Structured Natural Language Specifications - PowerPoint PPT Presentation

Automatically Generating Precise Oracles from Structured Natural Language Specifications http://swami.cs.umass.edu Manish Motwani Yuriy Brun The Test Oracle Problem Software Under Input Actual Output Test The Test Oracle Problem Software


  1. Automatically Generating Precise Oracles from Structured Natural Language Specifications http://swami.cs.umass.edu Manish Motwani Yuriy Brun

  2. The Test Oracle Problem Software Under Input Actual Output Test

  3. The Test Oracle Problem Software Under Input Actual Output Test Test Oracle (Expected Output) Correct Incorrect

  4. The Test Oracle Problem Software Under Input Actual Output Test Easy to Test Oracle generate (Expected Output) Correct Incorrect

  5. The Test Oracle Problem Software Under Input Actual Output Test Easy to Test Oracle generate (Expected Output) Correct Incorrect Hard to generate

  6. Our Solution - Swami Structured Informal Specification

  7. Our Solution - Swami Structured Informal Specification Executable Test /*TEST TEMPLATE WITH ORACLE*/ function test_array_len( len ){ if ( ToUint32(len)!=len) { try{ var output = new Array ( len ); return; }catch(e){ assert.strictEqual(true, (e instanceof RangeError)); return; } } Test oracle } /*TEST INPUTS*/ test_array_len(1.1825863363010669e+308); test_array_len(null); Swami test_array_len(-747); Test inputs test_array_len(368); … http://swami.cs.umass.edu

  8. Why JavaScript specifications?

  9. Why JavaScript specifications? Does not get deprecated

  10. Why JavaScript specifications? Does not get deprecated Less ambiguous

  11. Why JavaScript specifications? Does not get deprecated Less ambiguous Multiple real-world projects adhere to the spec

  12. Swami-generated tests are precise to the specification Number of Tests (total 83,000) Innocuous tests 50,086 (60.4%)

  13. Swami-generated tests are precise to the specification Number of Tests (total 83,000) Innocuous tests 32,379 Good tests (39.0%) 50,086 (60.4%)

  14. Swami-generated tests are precise to the specification Number of Tests (total 83,000) Bad tests (0.6%) 535 Innocuous tests 32,379 32,379 Good tests (39.0%) 50,086 (60.4%)

  15. Swami-generated tests are precise to the specification Number of Tests (total 83,000) Bad tests (0.6%) 535 Innocuous tests 32,379 32,379 Good tests (39.0%) 50,086 (60.4%) Of the non-innocuous tests, 98.4% are Good and only 1.6% are Bad

  16. Swami covers more code and identifies features and bugs missed by developer-written tests Missing Features / Bugs • 15 missing features in Rhino • 1 unknown bug in Rhino and Node.js • 18 semantic disambiguities in JavaScript specification

  17. Swami covers more code and identifies features and bugs missed by developer-written tests Code Coverage Ratio Missing Features / Bugs • 15 missing features in Rhino 19.3% 15.2% • 1 unknown bug in Rhino and Node.js • 18 semantic disambiguities in line coverage branch coverage JavaScript specification Developer Developer+Swami

  18. Swami generates fewer false alarms and covers code missed by EvoSuite Number of False Alarms Code Coverage Ratio 73.9% 19.5% bad tests line coverage EvoSuite Swami EvoSuite EvoSuite+Swami

  19. Swami identifies the specifications that encode testable behavior precisely performance using rule-based approach performance using IR-based approach 100.00% 100.00% 80.00% 80.00% 60.00% 60.00% 40.00% 40.00% 20.00% 20.00% 0.00% 0.00% precision recall precision recall

  20. Why is it hard to derive oracles from informal specifications?

  21. Why is it hard to derive oracles from informal specifications? Encode testable behavior

  22. Why is it hard to derive oracles from informal specifications? Encode testable Abstract behavior Operations

  23. Why is it hard to derive oracles from informal specifications? Encode testable Abstract Implicit behavior Operations Operations

  24. Why is it hard to derive oracles from informal specifications? Oracles Encode testable Abstract Implicit embedded in behavior Operations Operations Conditionals

  25. Why is it hard to derive oracles from informal specifications? Assignments Oracles Encode testable Abstract Implicit using local embedded in behavior Operations Operations variables Conditionals

  26. Why is it hard to derive oracles from informal specifications? Assignments Oracles Ambiguous and Encode testable Abstract Implicit using local embedded in Deprecated behavior Operations Operations variables Conditionals

  27. Related work: What can the state-of-the-art tools do? Assignments Oracles Ambiguous and Encode testable Abstract Implicit using local embedded in Deprecated behavior Operations Operations variables Conditionals • EvoSuite 1 , Randoop 2 • Cannot derive oracles from natural language specifications • Generated tests cannot identify missing features • Jdoctor 3 , Toradocu 4 , @tComment 5 • Closely tied to JavaDoc (use tags, e.g., @params, @throws) and Randoop, hence may not generalize 1. Fraser et al. TSE 2013, 2. Pacheco et al. ICSE 2007, 3. Blasi et al. ISSTA 2018, 4. Goffi et al. ISSTA 2016 , 5. Tan et al. ICST 2012

  28. Related work: What can the state-of-the-art tools do? Assignments Oracles Ambiguous and Encode testable Abstract Implicit using local embedded in Deprecated behavior Operations Operations variables Conditionals • EvoSuite 1 , Randoop 2 • Cannot derive oracles from natural language specifications • Generated tests cannot identify missing features • Jdoctor 3 , Toradocu 4 , @tComment 5 • Closely tied to JavaDoc (use tags, e.g., @params, @throws) and Randoop, hence may not generalize State-of-the-art tools are not capable of deriving test oracles from informal specifications that exists independent of the source code. 1. Fraser et al. TSE 2013, 2. Pacheco et al. ICSE 2007, 3. Blasi et al. ISSTA 2018, 4. Goffi et al. ISSTA 2016 , 5. Tan et al. ICST 2012

  29. What kind of oracles exist in informal specifications? Vague oracles for common inputs Concrete oracles for uncommon inputs

  30. What kind of oracles exist in informal specifications? Vague oracles for common inputs Concrete oracles for uncommon inputs Informal specifications typically contain oracles for Exceptions and Boundary conditions .

  31. Is it useful to generate tests only for Exceptions and Boundary conditions? • 10 popular, well-tested open source libraries • The coverage of throw statements is usually significantly lower than overall coverage, in two cases below 50% Source: Goffi , Alberto, et al. “Automatic generation of oracles for exceptional behaviors.” ISSTA, 2016.

  32. Is it useful to generate tests only for Exceptions and Boundary conditions? • 10 popular, well-tested open source libraries • The coverage of throw statements is usually significantly lower than overall coverage, in two cases below 50% Exceptions are under-tested by the developers Source: Goffi , Alberto, et al. “Automatic generation of oracles for exceptional behaviors.” ISSTA, 2016.

  33. Goal of this work Structured encode Informal testable specification behavior Abstract Operations Implicit Operations Oracles embedded in Conditionals Executable Test Assignments Automatically generate using local executable tests (inputs with oracles) for variables Test inputs Exceptions and Boundary conditions from Ambiguous structured informal specifications Test oracles and deprecated

  34. Swami Structured encode Informal testable specification behavior Abstract Operations Implicit Operations Oracles embedded in Conditionals Executable Test Assignments Automatically generate using local executable tests (inputs with oracles) for variables Test inputs Exceptions and Boundary conditions from Ambiguous structured informal specifications Test oracles and deprecated

  35. Step1: Identify specifications which encode testable behavior Specification Relevant Document Specifications Rule-based approach Rules are regular expressions composed of POS tags, keywords, and wild card characters

  36. Step1: Identify specifications which encode testable behavior Specification Relevant Document Specifications Rule-based approach Heading RE: [CD new* NN LRB NN.* RRB] Body RE: [If .* return .*] [if .* throw .* exception]

  37. Step1: Identify specifications which encode testable behavior Specification Relevant Document Specifications Rule-based approach when the format of specification document is unknown Information Retrieval-based Source code approach OKAPI model

  38. Example specification encoding Relevant testable behavior Specifications Header RE: CD new* NN LRB NN.* RRB

  39. Example specification encoding Relevant testable behavior Specifications Header RE: CD new* NN LRB NN.* RRB Body RE: If .* throw .* exception Body RE: If .* return .*

  40. Step2: Extract method signature from specification heading and initialize Test Template

  41. Step2: Extract method signature from specification heading and initialize Test Template function test_< method name >(thisObj,<[ method args ]>) {} Initialized Test Template function test_string_prototype_startswith(thisObj,searchString,position) {}

  42. Step2: Extract method signature from specification heading and initialize Test Template function test_< method name >(thisObj,<[ method args ]>) {} Initialized Test Template function test_string_prototype_startswith(thisObj,searchString,position) {} new String(thisObj).startsWith(searchString, position); Method invocation code

Recommend


More recommend