ECE122 L17: Method Development and Testing April 5, 2007 ECE 122 Engineering Problem Solving with Java Lecture 17 Method Development and Testing.

Slides:



Advertisements
Similar presentations
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Advertisements

Interfaces A Java interface is a collection
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
Problem Solving #1 ICS Outline Review of Key Topics Review of Key Topics Example Program Example Program –Problem 7.1 Problem Solving Tips Problem.
Chapter 3, More on Classes & Methods Clark Savage Turner, J.D., Ph.D. Copyright 2003 CSTurner, from notes and text.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Chapter Day 17. © 2007 Pearson Addison-Wesley. All rights reserved6-2 Agenda Day 17 Problem set 3 posted  10 problems from chapters 5 & 6  Due in 3.
Chapter 6 Object-Oriented Design. © 2004 Pearson Addison-Wesley. All rights reserved6-2 Object-Oriented Design Now we can extend our discussion of the.
Enhancing classes Visibility modifiers and encapsulation revisited
ECE122 L13: Arrays of Objects March 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 13 Arrays of Objects.
Chapter 4: Writing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 4: Writing Classes Presentation slides for Java Software Solutions Foundations of Program Design Third Edition by John Lewis and William Loftus.
1 Miscellaneous Java … a collection of short topics that we need to get to at some point …
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Methods in Java Selim Aksoy Bilkent University Department of Computer Engineering
Chapter 2: Algorithm Discovery and Design
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Testing. Definition From the dictionary- the means by which the presence, quality, or genuineness of anything is determined; a means of trial. For software.
Chapter 6 Object-Oriented Design Part 3. © 2004 Pearson Addison-Wesley. All rights reserved 2/35 Outline Software Development Activities Identifying Classes.
© 2004 Pearson Addison-Wesley. All rights reserved November 9, 2007 Method Design & Method Overloading ComS 207: Programming I (in Java) Iowa State University,
Invitation to Computer Science, Java Version, Second Edition.
Classes and Methods Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
© 2006 Pearson Education Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Copyright © 2002, Systems and Computer Engineering, Carleton University a-JavaReview.ppt * Object-Oriented Software Development Unit.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
Chapter 1 Program design Objectives To describe the steps in the program development process To introduce the current program design methodology To introduce.
Chapter 6 Object-Oriented Design Part 3. © 2004 Pearson Addison-Wesley. All rights reserved6-2 Outline Enumerated Types Revisited Method Design Testing.
Programming in Java (COP 2250) Lecture 14 & 15 Chengyong Yang Fall, 2005.
Programming in Java (COP 2250) Lecture Chengyong Yang Fall, 2005.
1 CSC 221: Computer Programming I Spring 2008 course overview  What did we set out to learn?  What did you actually learn?  Where do you go from here?
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
1 Object-Oriented Design Now we can extend our discussion of the design of classes and objects Chapter 6 focuses on: software development activities determining.
© 2004 Pearson Addison-Wesley. All rights reserved April 14, 2006 Polymorphism ComS 207: Programming I (in Java) Iowa State University, SPRING 2006 Instructor:
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
Lecture 4 b Writing Classes b class declarations b method declarations b constructors b instance variables b encapsulation b method overloading b program.
1 Object-Oriented Design Now we can extend our discussion of the design of classes and objects Chapter 6 focuses on: software development activities determining.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Systems Design.  Application Design  User Interface Design  Database Design.
© 2004 Pearson Addison-Wesley. All rights reserved November 12, 2007 Inheritance ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Testing JUnit Testing. Testing Testing can mean many different things It certainly includes running a completed program with various inputs It also includes.
© 2004 Pearson Addison-Wesley. All rights reserved April 10, 2006 Inheritance (part 2) ComS 207: Programming I (in Java) Iowa State University, SPRING.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
UML Diagrams and Software Testing Instructor: Scott Kristjanson CMPT 135 SFU Surrey, Spring 2016.
© 2004 Pearson Addison-Wesley. All rights reserved April 5, 2006 Method Design & Method Overloading ComS 207: Programming I (in Java) Iowa State University,
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
Chapter VII: Arrays.
Chapter 7 Object-Oriented Design
Programming Logic and Design Seventh Edition
More About Objects and Methods
Software Testing.
Chapter 4: Writing Classes
Inheritance November 10, 2006 ComS 207: Programming I (in Java)
Inheritance April 7, 2006 ComS 207: Programming I (in Java)
Phil Tayco Slide version 1.0 Created Oct 2, 2017
CSCI 1100/1202 April 10,
Classes, Encapsulation, Methods and Constructors (Continued)
CS139 October 11, 2004.
CSE 1020:Software Development
Presentation transcript:

ECE122 L17: Method Development and Testing April 5, 2007 ECE 122 Engineering Problem Solving with Java Lecture 17 Method Development and Testing

ECE122 L17: Method Development and Testing April 5, 2007 Outline °Problem: How can I handle more complicated method design °Splitting up problems into a series of steps Algorithms °What gets passed between the methods Method overloading °Software testing

ECE122 L17: Method Development and Testing April 5, 2007 Method Design °As we've discussed, high-level design issues include: identifying primary classes and objects assigning primary responsibilities °After establishing high-level design issues, Important to address low-level issues such as the design of key methods °For some methods, careful planning is needed to make sure they contribute to program design

ECE122 L17: Method Development and Testing April 5, 2007 Method Design °An algorithm is a step-by-step process for solving a problem °Examples: a recipe, travel directions °Every method implements an algorithm that determines how the method accomplishes its goals °An algorithm may be expressed in pseudocode An outline of a program, written in a form that can easily be converted into real programming statementsprogramprogrammingstatements while not at end of list compare adjacent elements if second is greater than first switch them get next two elements if elements were switched repeat for entire list Sorting

ECE122 L17: Method Development and Testing April 5, 2007 Method Decomposition °A method should be relatively small, so that it can be understood as a single entity °A potentially large method should be decomposed into several smaller methods as needed for clarity °A public service method of an object May call one or more private support methods to help it accomplish its goal °Support methods might call other support methods if appropriate

ECE122 L17: Method Development and Testing April 5, 2007 Objects as Parameters °Another important issue related to method design involves parameter passing °Parameters in a Java method are passed by value °A copy of the actual parameter (the value passed in) is stored into the formal parameter In the method header °Passing parameters is similar to an assignment statement °When an object is passed to a method, the actual parameter and the formal parameter become aliases of each other

ECE122 L17: Method Development and Testing April 5, 2007 Passing Objects to Methods °What a method does with a parameter may or may not have a permanent effect (outside the method) °Difference between changing the internal state of an object versus changing the object reference °For primitives: copy of data value passed °For arrays: reference passed °For objects: reference passed °For arrays and other objects, data change is permanent

ECE122 L17: Method Development and Testing April 5, 2007 Method Overloading °Method overloading is the process of giving a single method name multiple definitions °The method name is not sufficient to determine which method is being called °The signature of each overloaded method must be unique °The signature includes the number, type, and order of the parameters

ECE122 L17: Method Development and Testing April 5, 2007 Method Overloading °The compiler determines which method is being invoked by analyzing the parameters float tryMe(int x) { return x +.375; } float tryMe(int x, float y) { return x*y; } result = tryMe(25, 4.32) Invocation

ECE122 L17: Method Development and Testing April 5, 2007 Method Overloading °The println method is overloaded: println (String s) println (int i) println (double d) and so on... °The following lines invoke different versions of the println method: System.out.println ("The total is:"); System.out.println (total);

ECE122 L17: Method Development and Testing April 5, 2007 Overloading Methods °The return type of the method is not part of the signature °That is, overloaded methods cannot differ only by their return type °Constructors can be overloaded °Overloaded constructors provide multiple ways to initialize a new object The correct parameter list must be specified when the object is created

ECE122 L17: Method Development and Testing April 5, 2007 Testing °Testing can mean many different things °It certainly includes running a completed program with various inputs °It also includes any evaluation performed by human or computer to assess quality °Some evaluations should occur before coding even begins °The earlier we find an problem, the easier and cheaper it is to fix

ECE122 L17: Method Development and Testing April 5, 2007 Testing °The goal of testing is to find errors °As we find and fix errors, we raise our confidence that a program will perform as intended °We can never really be sure that all errors have been eliminated °So when do we stop testing? Conceptual answer: Never Snide answer: When we run out of time Better answer: When we are willing to risk that an undiscovered error still exists

ECE122 L17: Method Development and Testing April 5, 2007 Reviews °A review is a meeting in which several people examine a design document or section of code °It is a common and effective form of human-based testing °Presenting a design or code to others: makes us think more carefully about it provides an outside perspective °Reviews are sometimes called inspections or walkthroughs

ECE122 L17: Method Development and Testing April 5, 2007 Test Cases °A test case is a set of input and user actions, coupled with the expected results °Often test cases are organized formally into test suites which are stored and reused as needed °For medium and large systems, testing must be a carefully managed process °Many organizations have a separate Quality Assurance (QA) department to lead testing efforts

ECE122 L17: Method Development and Testing April 5, 2007 Defect and Regression Testing °Defect testing is the execution of test cases to uncover errors °The act of fixing an error may introduce new errors °After fixing a set of errors we should perform regression testing Running previous test suites to ensure new errors haven't been introduced °It is not possible to create test cases for all possible input and user actions °Therefore we should design tests to maximize their ability to find problems

ECE122 L17: Method Development and Testing April 5, 2007 Black-Box Testing °In black-box testing, test cases are developed without considering the internal logic °They are based on the input and expected output °Input can be organized into equivalence categories °Two input values in the same equivalence category would produce similar results °A good test suite will cover all equivalence categories and focus on the boundaries

ECE122 L17: Method Development and Testing April 5, 2007 White-Box Testing °White-box testing focuses on the internal structure of the code °The goal is to ensure that every path through the code is tested °Paths through the code are governed by any conditional or looping statements in a program °A good testing effort will include both black-box and white-box tests

ECE122 L17: Method Development and Testing April 5, 2007 Summary °Method design is critical to successful program implementation Can’t be too complicated but must cover basics °Becoming familiar with method design is really a matter of practice Learning through doing °Method overloading is an important feature of OOP Allows for different choices in using methods °Whole courses cover software testing. This course primarily examines using the debugger in DrJava