apcs ab java n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
APCS-AB: Java PowerPoint Presentation
Download Presentation
APCS-AB: Java

Loading in 2 Seconds...

play fullscreen
1 / 12

APCS-AB: Java - PowerPoint PPT Presentation


  • 294 Views
  • Uploaded on

APCS-AB: Java. Unit Testing Information today from “Unit Testing in BlueJ” http://www.bluej.org/tutorial/testing-tutorial.pdf October 28, 2005. Unit Testing. The individual testing of separate units of a software system In Scheme, we tested each function we wrote

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'APCS-AB: Java' - albert


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
apcs ab java

APCS-AB: Java

Unit Testing

Information today from “Unit Testing in BlueJ”

http://www.bluej.org/tutorial/testing-tutorial.pdf

October 28, 2005

unit testing
Unit Testing
  • The individual testing of separate units of a software system
    • In Scheme, we tested each function we wrote
    • In Java, we are going to test individual classes and methods
  • BlueJ uses JUnit, a regression testing framework
    • Regression testing basically allows a programmer to rerun tests at anytime to make sure that recent changes/additions haven’t broken code
    • More information about JUnit at their website; www.junit.org
to use testing
To use Testing
  • Need to set a BlueJ preference to Show testing tools
  • Then you get new buttons on the interface
testing
Testing
  • Now when you right-click on an object, you can choose to “Create Test Class”
  • Doing so will create a new class that is linked to the class being tested
test class
Test Class
  • The Test Class Menu gives the programmer several options
testing methods
Testing Methods
  • When you choose “Create Test Method” you will be prompted to enter a name for the test
    • test methods always start with the prefix “test” and it will be automatically added if you don’t put it (so “testName” and “name” would both create a method called “testName”
  • Then everything you do after clicking OK will be recorded as part of the test (until you click the “End” or “Cancel” buttons)
recording the test
Recording the test
  • Make an object
  • Call methods, entering parameters as needed
  • When you get a result dialog, you can make an assertion
running tests
Running Tests
  • If we right-click the test class, we can choose to “Test All” or we can choose individual tests to run
reducing overhead
Reducing Overhead
  • Instead of creating the object each time we are running a set of tests (especially if a given problem requires us to create multiple objects), we can create the objects once on the object bench and then choose “Object Bench to Test Fixture”
    • This will create the initial scenario for all test methods that you create
writing by hand
Writing By Hand
  • You may also choose to make test cases by hand - making the source code just like any other class
    • But you need to follow the JUnit guidelines
      • Class extends junit.framework.TestCase
      • One method setUp()
      • One void method for each test, method names starting with “test”
      • assertEquals method call to check values
extreme programming
eXtreme Programming
  • A way of approaching software design
  • Says that you should create test cases before the implementation of a method
    • In BlueJ, that means either:
      • Doing it by hand
      • Make “stub” methods first (with dummy values being returned) then make the test cases interactively, making the assertions according to expectations of the finished program
lab projects from book
Lab: Projects From book
  • Design a class with one method that takes an integer value as a parameter and prints the sum of all even integers between 2 and the integer value, inclusive.
    • Design and program appropriate test cases
  • Design and implement an application that reads an integer value representing a year from the user. The purpose pf the program is to determine if the year is a leap year (and therefore has 29 days in February) in the Gregorian calendar. A year is a leap year if it is divisible by 4, unless it is also divisible by 100 but not 400. For example, the year 2003 is not a leap year, but 2004 is. The year 1900 is not a leap year because it is divisible by 100, but the year 200 is a leap year because even though it is divisible by 100, it is also divisible by 400. Produce an error message for any input less than 1582 (the year the Gregorian calendar was adopted).
    • Design and program appropriate test cases. Hint: use all the examples given in the problem statement