Download presentation
Presentation is loading. Please wait.
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 Regression testing Alternatives:
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 × 2-4
9
More information for doubles
More on float and doubles: 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.