Java IO and Testing made simple - PowerPoint PPT Presentation

About This Presentation
Title:

Java IO and Testing made simple

Description:

made simple. Viera K. Proulx and Richard Rasala. College of Computer and ... Java IO and Testing Made Simple. User interactions. prompt displayed in the console ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 26
Provided by: tri5425
Category:
Tags: java | made | simple | testing

less

Transcript and Presenter's Notes

Title: Java IO and Testing made simple


1
Java IOand Testingmade simple
  • Viera K. Proulx and Richard Rasala
  • College of Computer and Information Science
  • Northeastern University
  • Boston MA
  • vkp_at_ccs.neu.edu
  • rasala_at_ccs.neu.edu

2
Java IO and Testing Made Simple
  • Teaching with Java many problems
  • We address three of them
  • User interactions
  • Test suite development
  • Small vs. large data sets for algorithms

3
Java IO and Testing Made Simple
  • Reading user input
  • from console or from GUI
  • complicated
  • buggy
  • convoluted
  • repetitious
  • illustrates bad programming in the best way

4
Java IO and Testing Made Simple
  • Test suite development
  • ad hoc
  • cumbersome
  • no organization
  • (or) overwhelming (JUnit)
  • unreadable
  • bad habits early

5
Java IO and Testing Made Simple
  • Small vs. large data sets for algorithms
  • internal data vs. external data
  • treated differently
  • programs are re-written for file input
  • omitted from most text books
  • no understanding of the need for stress tests
  • ... bad habits early...

6
Java IO and Testing Made Simple
  • Solutions
  • toolkit support for type-safe robust input
  • from console and GUI
  • with well designed user interface
  • framework to support separate test class
  • to act as a client class encapsulates the test
    suite
  • leverage abstractions of traversals via iterators
  • to supply data for algorithm testing

7
User interactions
  • Reading user input
  • from console or from GUI
  • requires parsing, conversion, error reporting
  • JPT toolkit
  • one method does it all
  • uniform for console and GUI

8
User interactions
  • prompt displayed in the console
  • input string is parsed
  • expressions are evaluated and converted
  • errors reported awaiting user correction
  • value of the correct type delivered
  • option to cancel input is available

9
User interactions
  • In student code
  • int x console.in.demandInt(Number)
  • In console program output user input system
    error
  • Number 34x
  • Expected end of expression.
  • 34x
  • Number 34

10
User interactions
  • or for GUI TextFieldView xTFV
  • int x
  • try
  • x xTFV.requestDouble( )
  • catch (CancelledException e)
  • System.out.println(Input ends)

11
User interactions
  • Input of compound data entire object
  • in real life Serializable (unreadable)
  • For student programs we want to deliver
  • an instantiated object in one method call
  • Person p testClass.demandPerson(P)

12
User interactions
  • Person p testClass.demandPerson(P)
  • Person demandPerson(String prompt)
  • console.out.println(prompt)
  • return new Person(
  • console.in.demandString(Name),
  • console.in.demandInt(Age),
  • console.in.demandBoolean(Married?))

13
User interactions
  • for GUIs
  • we can build a custom GUI that delivers
  • compete Person instance
  • PersonView pView new PersonView(...)
  • Person p pView.demandPerson( )
  • (JPT makes this easy - we really mean it)

14
Test Suite Development
  • interface Comparable...
  • class Person...
  • class Address...
  • abstract class Job...
  • class Clerk extends Job...
  • Test goals
  • Create objects in classes
  • Person, Address, Clerk
  • Test
  • methods in all classes
  • Tests illustrate
  • the use of objects and classes
  • in real programs

15
Test Suite Development
  • Test class requirements
  • needs to instantiate objects in target classes
  • needs to test methods in target classes
  • they should be grouped by the target class
  • there should be a comment on the purpose
  • needs an option to run only some tests
  • access to user input and output graphics, GUI

16
Test Suite Development
  • Java Power Framework
  • TestClass constructor invokes an application
    that provides
  • access to the JPT console and its methods
  • access to a buffered graphics window
  • a button for each proper method in TestClass
  • proper method void, no arguments

17
Test Suite Development
  • public class TestSuite extends JPFalt
  • public static void main(String args)
  • new TestSuite( )
  • Person p new Person(Roger, 34, true)
  • void testIsOld( )
  • testHeader(isOld)
  • expected(false)
  • actual(p.isOld( ))

18
Test Suite Development
  • Sample test results in the console
  • Testing method isOld
  • Expected false
  • Actual false
  • expected(arg) and actual(arg) methods
  • are implemented for all primitive types
  • and for Object with toString() method
  • (Students implement toString() for all classes)

19
Input of Data Sets
  • Sorting algorithms, Hash tables, Graphs, etc.
  • sort a List of Person-s by age
  • sort an Array of Person-s by name
  • List, Array a Collection
  • by age, by name a Comparator
  • what data to sort? - typically students change
    the code for different sources

20
Input of Data Sets
  • Goal
  • sort any data that implements Collection
  • use the given Comparator
  • use the given data source
  • Solution
  • provide an iterator for the data source
  • copy the data into your kind of Collection

21
Input of Data Sets
  • Iterator for the data source (interface IRange)
  • modified to fit Java for-loop
  • delivers current object without advancing
  • For each data set used in algorithms
  • provide method in algorithm setup class
  • DataSet initialize(IRange it)

22
Input of Data Sets
  • Implementing the iterator
  • for input from the console
  • we already can input complete objects
  • for input from GUI same idea
  • for input from existing test data
  • for input from a file
  • helper extracts object data from a line

23
Input of Data Sets
  • Examples
  • DataSet ds1 algSetup.initialize(
  • new MyDataRange(someData))
  • DataSet ds2 algSetup.initialize(
  • new MyConsoleRange())
  • DataSet ds3 algSetup.initialize(
  • new MyFileRange(myFile.txt))

24
Java IO and Testing Made Simple
  • User interactions
  • Test suite development
  • Input of data sets
  • Good Habits Early
  • Student experience uniformly positive

25
Java IO and Testing Made Simple
  • http//www.ccs.neu.edu/jpt
  • New initiatives and a workshop
  • http//www.ccs.neu.edu/home/vkp
Write a Comment
User Comments (0)
About PowerShow.com