1 / 11

BlueJ Tester

BlueJ 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

heidi-dixon
Télécharger la présentation

BlueJ Tester

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BlueJ Tester By Pepper

  2. 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

  3. 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 BlueJ interface) • Code tests in main method (and verify results and print notices for failure)

  4. 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.TestCase import tester.*; public class MyPgmTest {

  5. Test a Static Method’s Return • Fill in testSomething method • 3 parts: • Command : t.checkExpect • Method call: MyPgm.addIt(3) • Method return: 6 • t.checkExpect( MyPgm.addIt(3) , 6 ); • Make many tests • t.checkExpect(MyPgm.addIt(3),6); • t.checkExpect(MyPgm.addIt(5),5);

  6. Complete Test Program import tester.*; public class MyPgmTest { public static void testEverything () { Tester.run (new MyPgmTest()); } public void testSomething (Tester t) { t.checkExpect (MyPgm.addIt(2),5); t.checkExpect (MyPgm.addIt(2),4); } }

  7. Run Tests • Right click on test block and compile • Right click on test block and run testEverything() • See the results of each test in the terminal window • Note: You can add other methods if you like

  8. Testing Double Value Matching • How to represent 1.1? • The problem: between 1/8 and 1/16 • 1.10011001100110011001101 × 2-4 • .000110011001100110011001101

  9. More information for doubles • More on float and doubles: http://docs.oracle.com/cd/E19957-01/806-3568/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

  10. Inexact - Checking Doubles • Check doubles by only insisting on .001 tolerance. • 4 parts: • Command : t.checkInexact • Method call: MyPgm.addIt(3) • Method return: 6 • Tolerance: .001 • t.checkInexact( MyPgm.addIt(3) , 6, .001 );

  11. 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

More Related