Java IO and Testing made simple

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

J-Unit Framework.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
Java Power Tools: A Foundation for Interactive GUI Exploration Viera K. Proulx, Richard Rasala, Jeff Raab HCI 2001 Conference New Orleans, LA August 10,
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Chapter 7 Improving the User Interface
Scanner class for input Instantiate a new scanner object Scanner in = new Scanner(System.in); Getting input using scanner – int i = scanner.nextInt() –
CS 206 Introduction to Computer Science II 01 / 23 / 2009 Instructor: Michael Eckmann.
Unit Testing Discussion C. Unit Test ● public Method is smallest unit of code ● Input/output transformation ● Test if the method does what it claims ●
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Java Power ToolsNortheastern CCS EdGroup Java Power Tools Model Software for Teaching Object-Oriented Design Richard Rasala Jeff Raab Viera Proulx
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
Ex3 Preview, Swing tutorial Ex1 review Amit Shabtay.
SIMPLE PROBLEM SOLVING in Java: a Problem Set Framework Viera K. Proulx Richard Rasala Jason Jay Rodrigues CCSCNE 2002 Conference.
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
In the name of Allah The Proxy Pattern Elham moazzen.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Java Classes. Consider this simplistic class public class ProjInfo {ProjInfo() {System.out.println("This program computes factorial of number"); System.out.println("passed.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
The SIGCSE 2001 Maze Demonstration Program Richard Rasala, Jeff Raab, Viera K. Proulx College of Computer Science Northeastern University Boston MA
Object Serialization.  When the data was output to disk, certain information was lost, such as the type of each value.  If the value "3" is read from.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Lecture 5:Interfaces and Abstract Classes
CSC 222: Object-Oriented Programming
The need for Programming Languages
INF230 Basics in C# Programming
University Of Karachi Department Of Computer Science
Ch 10- Advanced Object-Oriented Programming Features
Lecture 27 Creating Custom GUIs
CS 153: Concepts of Compiler Design November 30 Class Meeting
Java Programming: Guided Learning with Early Objects
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
PRG 421 MART Higher Education / prg421mart.com
PRG 421 GUIDE Lessons in Excellence -- prg421guide.com.
Tutorial C#.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Chapter 17 Binary I/O Dr. Clincy - Lecture.
Advanced Programming Lecture 02: Introduction to C# Apps
Fundamental Error Handling
Functional interface.
Constructors, GUI’s(Using Swing) and ActionListner
Introduction to Data Structure
CMPE212 – Reminders Assignment 3 due next Friday.
Defining Classes and Methods
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
LCC 6310 Computation as an Expressive Medium
Winter 2019 CMPE212 5/25/2019 CMPE212 – Reminders
Software Design Lecture : 39.
Review for Midterm 3.
CMSC 202 Threads.
Chapter 1: Creating a Program.
Presentation transcript:

Java IO and Testing made simple Viera K. Proulx and Richard Rasala College of Computer and Information Science Northeastern University Boston MA vkp@ccs.neu.edu rasala@ccs.neu.edu 3/5/2004 Java IO and Testing Made Simple

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 Java IO and Testing Made Simple 3/5/2004

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 Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple Test suite development ad hoc cumbersome no organization (or) overwhelming (JUnit) unreadable bad habits early Java IO and Testing Made Simple 3/5/2004

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... Java IO and Testing Made Simple 3/5/2004

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 Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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 Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 3/5/2004 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 Java IO and Testing Made Simple 3/5/2004 Java IO and Testing Made Simple

Java IO and Testing Made Simple 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 Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple User interactions or for GUI TextFieldView xTFV: int x; try{ x = xTFV.requestDouble( ); } catch (CancelledException e) { System.out.println(“Input ends”); Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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:”); Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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?:”)); } Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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) Java IO and Testing Made Simple 3/5/2004

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 Java IO and Testing Made Simple 3/5/2004

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 Java IO and Testing Made Simple 3/5/2004

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 Java IO and Testing Made Simple 3/5/2004

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( )); Java IO and Testing Made Simple 3/5/2004

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) Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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 Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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 Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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); Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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 Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple 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”)); Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple User interactions Test suite development Input of data sets Good Habits Early Student experience: uniformly positive Java IO and Testing Made Simple 3/5/2004

Java IO and Testing Made Simple http://www.ccs.neu.edu/jpt New initiatives and a workshop: http://www.ccs.neu.edu/home/vkp Java IO and Testing Made Simple 3/5/2004