Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Test Generation with JML Part I – JMLUnitNG Wojciech Mostowski, Gabriele Paganelli http://wwwhome.ewi.utwente.nl/~mostowskiwi/ http://www.cse.chalmers.se/~gabpag/ University of T wente Chalmers University of Technology Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Overview Part I ◮ JML as test oracle Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Overview Part I ◮ JML as test oracle ◮ Test data generation Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Overview Part I ◮ JML as test oracle ◮ Test data generation ◮ JMLTestNG Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Overview Part I ◮ JML as test oracle ◮ Test data generation ◮ JMLTestNG ◮ Good specifications for testing Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Overview Part I ◮ JML as test oracle ◮ Test data generation ◮ JMLTestNG ◮ Good specifications for testing Part II ◮ Provide even better test data with KeY Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References The Basic Idea Use JML specs to check I/O behaviour of methods Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References The Basic Idea Use JML specs to check I/O behaviour of methods ◮ Take the input test data, evaluate the precondition ◮ if true run the method with input data ◮ if false skip – meaningless test Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References The Basic Idea Use JML specs to check I/O behaviour of methods ◮ Take the input test data, evaluate the precondition ◮ if true run the method with input data ◮ if false skip – meaningless test ◮ After the execution of the method evaluate the postcondition ◮ if true – test passed ◮ if false – test fail, quote the values of the input data Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Running Example /*@ public normal_behavior requires param >= 0; ensures \result >= 10; also public normal_behavior requires param < 0; ensures \result < -10; @*/ public int makeHole( int param) { if (param >= 0) { return param + 10; } else { return param - 10; } } Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Running Example /*@ public normal_behavior ◮ Take param==0 , first requires param >= 0; precondition true, the first ensures \result >= 10; spec defines a meaningful also public normal_behavior test requires param < 0; ensures \result < -10; @*/ public int makeHole( int param) { if (param >= 0) { return param + 10; } else { return param - 10; } } Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Running Example /*@ public normal_behavior ◮ Take param==0 , first requires param >= 0; precondition true, the first ensures \result >= 10; spec defines a meaningful also public normal_behavior test requires param < 0; ◮ The second does not, skip ensures \result < -10; further checks @*/ public int makeHole( int param) { if (param >= 0) { return param + 10; } else { return param - 10; } } Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Running Example /*@ public normal_behavior ◮ Take param==0 , first requires param >= 0; precondition true, the first ensures \result >= 10; spec defines a meaningful also public normal_behavior test requires param < 0; ◮ The second does not, skip ensures \result < -10; further checks @*/ public int makeHole( int param) { ◮ Execute method, check if (param >= 0) { the postcondition(s) return param + 10; (true), test pass } else { return param - 10; } } Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Running Example /*@ public normal_behavior ◮ Take param==0 , first requires param >= 0; precondition true, the first ensures \result >= 10; spec defines a meaningful also public normal_behavior test requires param < 0; ◮ The second does not, skip ensures \result < -10; further checks @*/ public int makeHole( int param) { ◮ Execute method, check if (param >= 0) { the postcondition(s) return param + 10; (true), test pass } else { return param - 10; ◮ Test with other inputs. . . } } Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Running Example /*@ public normal_behavior ◮ Take param==0 , first requires param >= 0; precondition true, the first ensures \result >= 10; spec defines a meaningful also public normal_behavior test requires param < 0; ◮ The second does not, skip ensures \result < -10; further checks @*/ public int makeHole( int param) { ◮ Execute method, check if (param >= 0) { the postcondition(s) return param + 10; (true), test pass } else { return param - 10; ◮ Test with other inputs. . . } ◮ What inputs?! } Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Test Data Generation ◮ Primitive types: ◮ Choose characteristic and borderline values e.g. Integer.MIN_VALUE , -1 , 0 , 1 , Integer.MAX_VALUE Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Test Data Generation ◮ Primitive types: ◮ Choose characteristic and borderline values e.g. Integer.MIN_VALUE , -1 , 0 , 1 , Integer.MAX_VALUE ◮ Provide manual input: -872463 , 123316 Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Test Data Generation ◮ Primitive types: ◮ Choose characteristic and borderline values e.g. Integer.MIN_VALUE , -1 , 0 , 1 , Integer.MAX_VALUE ◮ Provide manual input: -872463 , 123316 ◮ Still may not be enough – KeY can do better Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Test Data Generation ◮ Primitive types: ◮ Choose characteristic and borderline values e.g. Integer.MIN_VALUE , -1 , 0 , 1 , Integer.MAX_VALUE ◮ Provide manual input: -872463 , 123316 ◮ Still may not be enough – KeY can do better ◮ Reference types: ◮ Objects created with default constructors Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Test Data Generation ◮ Primitive types: ◮ Choose characteristic and borderline values e.g. Integer.MIN_VALUE , -1 , 0 , 1 , Integer.MAX_VALUE ◮ Provide manual input: -872463 , 123316 ◮ Still may not be enough – KeY can do better ◮ Reference types: ◮ Objects created with default constructors ◮ Manual object factories. . . Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Test Data Generation ◮ Primitive types: ◮ Choose characteristic and borderline values e.g. Integer.MIN_VALUE , -1 , 0 , 1 , Integer.MAX_VALUE ◮ Provide manual input: -872463 , 123316 ◮ Still may not be enough – KeY can do better ◮ Reference types: ◮ Objects created with default constructors ◮ Manual object factories. . . We are getting close to regular, laborous test case writing Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Overview Basics Test Data JMLUnitNG Demo Good Specifications Examples References Test Data Generation ◮ Primitive types: ◮ Choose characteristic and borderline values e.g. Integer.MIN_VALUE , -1 , 0 , 1 , Integer.MAX_VALUE ◮ Provide manual input: -872463 , 123316 ◮ Still may not be enough – KeY can do better ◮ Reference types: ◮ Objects created with default constructors ◮ Manual object factories. . . We are getting close to regular, laborous test case writing ◮ Use reflection to create objects with arbitrary constructors Wojciech Mostowski & Gabriele Paganelli Test Generation with JML
Recommend
More recommend