Blue J Tester By Pepper What is Tester
Blue. J Tester By Pepper
What is Tester? • Tester makes it easy for you to run test cases through your method that returns a value. • You code the test cases • You run the one test • It reports all failures with expected vs actual
Why use tester • Unit testing – When you can count on a function working, it is makes debugging the main program easier – It is easier to fix a smaller amount of code • Regression testing – Guard against changes breaking code • Alternatives: – Call method frequently typing in values (if value can be entered through Blue. J interface) – Code tests in main method (and verify results and print notices for failure)
Test a Static Method’s Return • Right click on class box – create test class • Double click green unit test box to edit • Remove extends junit. framework. Test. Case import tester. *; public class My. Pgm. Test {
Test a Static Method’s Return • Fill in test. Something method • 3 parts: – Command : t. check. Expect – Method call: My. Pgm. add. It(3) – Method return: 6 – t. check. Expect( My. Pgm. add. It(3) , 6 ); • Make many tests • t. check. Expect(My. Pgm. add. It(3), 6); • t. check. Expect(My. Pgm. add. It(5), 5);
Complete Test Program import tester. *; public class My. Pgm. Test { public static void test. Everything () { Tester. run (new My. Pgm. Test()); } public void test. Something (Tester t) { t. check. Expect (My. Pgm. add. It(2), 5); t. check. Expect (My. Pgm. add. It(2), 4); } }
Run Tests • Right click on test block and compile • Right click on test block and run test. Everything() • See the results of each test in the terminal window • Note: You can add other methods if you like
Testing Double Value Matching • • How to represent 1. 1? The problem: between 1/8 and 1/16 1. 100110011001101 × 2 -4. 000110011001101
More information for doubles • More on float and doubles: http: //docs. oracle. com/cd/E 19957 -01/8063568/ncg_goldberg. html – Explains how values are held – Explains rounding rules – No need to learn how, just know to expect it slightly off with tolerance. 001
Inexact - Checking Doubles • Check doubles by only insisting on. 001 tolerance. • 4 parts: – Command : t. check. Inexact – Method call: My. Pgm. add. It(3) – Method return: 6 – Tolerance: . 001 – t. check. Inexact( My. Pgm. add. It(3) , 6, . 001 );
Summary • Use tester for unit and regression tests of methods with return values • Doubles (and float) are inexact storage of fractions, so expect tolerance needed • How to set up tests for exact and inexact • How to run tests • How to see results
- Slides: 11