Benefits of object-orientationorientation

Similar documents
Week 1 - Overview of HTML and Introduction to JavaScript

while (condition) { body_statements; for (initialization; condition; update) { body_statements;

Debugging in AnyLogic. Nathaniel Osgood CMPT

Lecture 15 Software Testing

Program Correctness and Efficiency. Chapter 2

CSE 374 Programming Concepts & Tools

About this exam review

Standard. Number of Correlations

Chapter 8 Software Testing. Chapter 8 Software testing

Software Testing Interview Question and Answer

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CSCA08 Winter Week 12: Exceptions & Testing. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough

FRESHER TRAINING PROGRAM [MANUAL/QTP/ALM/QC/SE/LR/DB/ANDROID] COURSE OVERVIEW

Verification and Validation

Testing is executing a system in order to identify any gaps, errors, or missing requirements in contrary to the actual requirements.

18-642: Unit Testing 1/31/ Philip Koopman

Testing. Prof. Clarkson Fall Today s music: Wrecking Ball by Miley Cyrus

Testing and Debugging

Unit Testing as Hypothesis Testing

Quadratic: the time that it takes to sort an array is proportional to the. square of the number of elements.

function makeline(length, ch){ var str = ""; if (length >= 3)

Overview. State-of-the-Art. Relative cost of error correction. CS 619 Introduction to OO Design and Development. Testing.

Software Testing CS 408

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

18-642: Unit Testing 9/18/ Philip Koopman

Test Automation. Fundamentals. Mikó Szilárd

The Dynamic Typing Interlude

Introduction to Embedded Systems. Lab Logistics

Manuel Oriol, CHCRC-C, Software Testing ABB

Terminology. There are many different types of errors and different ways how we can deal with them.

CS 210 Algorithms and Data Structures College of Information Technology and Engineering Weisberg Division of Engineering and Computer Science

CSE 403: Software Engineering, Fall courses.cs.washington.edu/courses/cse403/16au/ Unit Testing. Emina Torlak

Parallel Debugging. ª Objective. ª Contents. ª Learn the basics of debugging parallel programs

Software Engineering Fall 2015 (CSC 4350/6350) TR. 5:30 pm 7:15 pm. Rao Casturi 11/10/2015

Boca Raton Community High School AP Computer Science A - Syllabus 2009/10

Introduction to Problem Solving and Programming in Python.

Software Engineering Fall 2014

Sample Exam. Certified Tester Foundation Level

Computer Science and Software Engineering University of Wisconsin - Platteville 9-Software Testing, Verification and Validation

QUIZ Friends class Y;

EXAM Microsoft MTA Software Development Fundamentals. Buy Full Product.

Examination Questions Time allowed: 1 hour 15 minutes

Testing and Debugging

Text Input and Conditionals

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

Debugging and Handling Exceptions

CSCE 206: Structured Programming in C++

Introduction To Software Testing. Brian Nielsen. Center of Embedded Software Systems Aalborg University, Denmark CSS

Chapter 7 Control Statements Continued

Principles of Computer Science I

Course Content. Objectives of Lecture 18 Black box testing and planned debugging. Outline of Lecture 18

ENGR 102 Engineering Lab I - Computation

Software Design Models, Tools & Processes. Lecture 6: Transition Phase Cecilia Mascolo

Software Engineering (CSC 4350/6350) Rao Casturi

Chapter 10. Testing and Quality Assurance

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

CS 240 Final Exam Review

Software Testing. Testing: Our Experiences

Understanding the Program Run

Testing & Debugging TB-1

Object Oriented Programming

JCreator. Starting JCreator

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)

Algorithms and Data Structures Spring 2008

Computer Science II Lab 3 Testing and Debugging

CS 1110, LAB 3: MODULES AND TESTING First Name: Last Name: NetID:

Coding and Unit Testing! The Coding Phase! Coding vs. Code! Coding! Overall Coding Language Trends!

BridgePoint Modeling Exercises in Building Executable Models Mentor Graphics Corporation

Testing, Debugging, Program Verification

Object-Oriented Software Engineering Conquering Complex and Changing Systems. Chapter 9, Testing

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

CS354 gdb Tutorial Written by Chris Feilbach

Mathematics/Science Department Kirkwood Community College. Course Syllabus. Computer Science CSC142 1/10

Java Software Solutions for AP Computer Science 3rd Edition, Lewis et al. 2011

Foundations of object orientation

Introduction to Computation and Problem Solving

Full Stack Developer with Java

Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Testing. ECE/CS 5780/6780: Embedded System Design. Why is testing so hard? Why do testing?

Client-server application testing plan

Unit Testing as Hypothesis Testing

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Programming in Visual Basic with Microsoft Visual Studio 2010

Reliable programming

3D Graphics Programming Mira Costa High School - Class Syllabus,

Testing is the process of evaluating a system or its component(s) with the intent to find whether it satisfies the specified requirements or not.

First, let s just try to run the program. When we click the button we get the error message shown below:

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS SOFTWARE ENGINEERING

Mind Q Systems Private Limited

Chapter 15 Debugging

Objects First with Java

Module 3: New types of data

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

Comp 151. Control structures.

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims

CS 4387/5387 SOFTWARE V&V LECTURE 4 BLACK-BOX TESTING

Testing! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 6!

Extended Introduction to Computer Science CS1001.py Lecture 10, part A: Interim Summary; Testing; Coding Style

In-Memory Fuzzing in JAVA

Transcription:

ITEC 136 Business Programming Concepts Week 14, Part 01 Overview 1 Week 14 Overview Week 13 review What is an object? (three parts) State (properties) Identity (location in memory) Behavior (methods) 2

Week 14 Overview Week 13 review Custom JS objects Constructors this reference The prototype property of functions Benefits of object-orientationorientation Coupling and cohesion (among others) 3 Week 14 Overview Week 13 review 3 of the 5 pillars of OOP Abstraction Encapsulation Composition (code reuse, 2 kinds) 4

Week 14 Overview Week 13 review Exception handling Detection and correction of errors are at different places in code. Exceptions communicate between those places and alter the flow of execution throw keyword try/catch/finally blocks 5 Outcomes Week 14 Overview Select necessary and sufficient test cases. Use a debugger to examine a running program. Correct runtime errors through a debugger. 6

Outcomes Week 14 Overview Select necessary and sufficient test cases. Use a debugger to examine a running program. Correct runtime errors through a debugger. 7 ITEC 136 Business Programming Concepts Week 14, Part 02 Testing Concepts 8

Testing Concepts Testing in the SDLC 9 Testing Concepts Validation vs. verification Validation: A comparison of the system behavior against what the user actually needs. Have we build the right software? 10

Testing Concepts Validation vs. verification Validation: A comparison of the system behavior against what the user actually needs. Have we build the right software? Primarily the work of business analysts and designers. Critical to realworld software success. 11 Testing Concepts Validation vs. verification Validation: A comparison of the system behavior against what the user actually needs. Have we build the right software? Verification: A comparison of system behavior against the specification. Have we built the software right? 12

Testing Concepts Validation vs. verification Validation: A comparison of the system behavior against what the user actually needs. Have we build the right software? Verification: A comparison of system behavior against the specification. Have we built the software right? 13 Testing Concepts Validation vs. verification Validation: A comparison Primarily the work of of the software system and quality assurance behavior against engineers. what What the most user people actually think of when you say testing. needs. Have we build the right Our focus this week. software? Verification: A comparison of system behavior against the specification. Have we built the software right? 14

Testing Concepts Types of testing Unit testing: : A function or object designed to test the behavior of a another function or object. Operates in isolation of other objects. Provide known inputs to check against known outputs. Group together into a test suite. 15 Testing Concepts Test driven development If testing is good, then why not do it continuously? Clean up (refactor) the design Write a test case for new behavior Debug any new test case failures. Run all tests (watching new test fail) Write code to make new test case pass 16

Testing Concepts Types of testing Integration testing: : verifies the behavior of larger groupings of modules. Done after unit testing of each component part, yet before system testing. Exposes interface, design problems 17 Testing Concepts Types of testing System testing: : testing of the entire system assembled from major modules. Done after integration testing Load, security, stress, performance, reliability, etc. 18

Testing Concepts Types of testing Acceptance testing: : performed by subject matter experts just prior to release. Last chance for bug finding. Done after system testing. Sometimes called beta testing. Binary decision (go/no go for release). 19 Testing Concepts Types of testing Regression testing: : re-running running old test cases after every bug fix to ensure that the fix introduced no new bugs. Prevents cycling of bugs. Acts as a safety net. Permits refactoring (redesign of existing code) while maintaining quality. 20

Testing Concepts Black- vs. white-box testing Black-box testing: : treats the item under test as a black box, providing only inputs (both valid and invalid) and checking outputs. Does not exploit internal knowledge of how the code works. 21 Testing Concepts Black- vs. white-box testing White-box testing: : testing all paths through the software using carefully crafted inputs (both valid and invalid). Critical to achieve a high degree of test coverage,, i.e. the percentage of lines of code exercised by the tests. 22

ITEC 136 Business Programming Concepts Week 14, Part 03 Applied Unit Testing 23 Applied Unit Testing Unit tests must Be quick and easy to write Run in an automated way Provide value to the programmer Method Provide inputs Validate outputs 24

Applied Unit Testing How do we test this: function absolutevalue(number) { if (number < 0) return -number; return number; 25 Applied Unit Testing How do we test this: Simple way: function testabsolutevaluefunction() { if (5!= absolutevalue(-5)) alert("failed test 1"); if (5!= absolutevalue(5)) alert("failed test 2") 26

Applied Unit Testing How do we test this: Simple way: Advantages: Simple. Can be used for regression testing. function testabsolutevaluefunction() { if (5!= absolutevalue(-5)) alert("failed test 1"); if (5!= absolutevalue(5)) alert("failed test 2") 27 Applied Unit Testing How do we test this: Simple way: Advantages: Simple. Can be used for regression testing. function testabsolutevaluefunction() { Disadvantages: if (5!= absolutevalue(-5)) Not easily reused for alert("failed test 1"); other kinds of testing if (5!= absolutevalue(5)) Too many alerts alert("failed test 2") 28

Applied Unit Testing Building a unit testing framework Principles: Make unit testing easy Take away all the repetitive code Report errors succinctly 29 Applied Unit Testing Building a unit testing framework var tests = new UnitTester(); tests.addtests({ testnegative : function() { tests.assertequals(5, absolutevalue(-5));, testpositive : function() { tests.assertequals(5, absolutevalue(-5));, testnonnumber : function() { tests.assertequals("nan", "" + absolutevalue("x")); ); tests.runtests(); 30

Applied Unit Testing Building a unit testing framework var tests = new UnitTester(); Expected answer tests.addtests({ testnegative : function() { tests.assertequals(5, absolutevalue(-5));, testpositive : function() { Actual answer tests.assertequals(5, absolutevalue(-5));, testnonnumber : function() { tests.assertequals("nan", "" + absolutevalue("x")); ); tests.runtests(); 31 Applied Unit Testing Building a unit testing framework 32 function FailedTest(expected, actual) { this.expected = expected; this.actual = actual; FailedTest.prototype.toString = function() { return "expected: " + this.expected + ", actual: " + this.actual; A failed test throws a FailedTest exception capturing how it failed.

Applied Unit Testing Building a unit testing framework function UnitTester() { this.alltests = new Object(); this.failures = []; Compares expected and actual values. 33 UnitTester.prototype.assertEquals = function( expected, actual) { if (expected.equals &&!expected.equals(actual)) throw new FailedTest(expected, actual); else if (!(expected == actual)) throw new FailedTest(expected, actual); Applied Unit Testing Building a unit testing framework UnitTester.prototype.addTests = function(manytests) { for (index in manytests) { this.addtest(index, manytests[index]); UnitTester.prototype.addTest = function(name, test) { this.alltests[name] = test; Sets up test functions to run. 34

Applied Unit Testing Building a unit testing framework 35 UnitTester.prototype.runTests = function() { for (var index in this.alltests) { if (this.alltests[index] instanceof Function) { try { this.alltests[index](); Actually runs the test functions catch (exception) { this.failures.push(index + ": " + exception); alert(this.makeresultsstring()); Applied Unit Testing Building a unit testing framework UnitTester.prototype.makeResultsString = function() { var str = ""; for (var index in this.failures) { str += this.failures[index] + "\n"; if (str == "") Produces the results. return "All tests passed."; return str; 36

ITEC 136 Business Programming Concepts Week 14, Part 04 Selecting Test Cases 37 Selecting Test Cases Test coverage Making sure that all parts of your program are exercised by the test cases. Every direction of nested if/else structures Every possible case in a switch statement Every possible way a loop can be run Never iterating (pre-test only) Iterating once Iterating many times 38

Selecting Test Cases Test coverage Making sure that all kinds of data are tested An expected test case Corner cases Illegal inputs 39 Selecting Test Cases Test coverage Ex: calculating square roots Expected inputs: numbers from [1 n] Corner cases: 0, [0 1] Illegal inputs: negative numbers 40

Try it: Applied Unit Testing Write test cases using the testing framework to determine if your merge() function (which merges two separately sorted arrays) works on many different data sets. 41 Try it: Applied Unit Testing Write test cases using the testing framework to determine if a sorting algorithm actually sorts arrays. 42

Try it: Applied Unit Testing Write a function that builds a histogram table at 10% intervals (i.e. given an array of data in the range [0, 100] output an array with 11 buckets containing the count of elements that fall in those buckets). Write tests to verify that it works. 43 ITEC 136 Business Programming Concepts Week 14, Part 05 Debugging Tools 44

Debugging Tools Old school approach Logging: debugging statements placed strategically in program code. function log(div, message) { document.getelementbyid(div).innerhtml += message + "<br />"; // then later... if (debug == true) { log("debug", "Got to here"); 45 Debugging Tools New school approach Logging: use the built in Firebug logging console! console.log("this is a log message"); console.info("this is an info message"); console.warn("this is a warn message"); console.error("this is an error message"); 46

Debugging Tools New school approach Logging: use the built in Firebug logging console! console.log("this is a log message"); console.info("this is an info message"); console.warn("this is a warn message"); console.error("this is an error message"); 47 Debuggers 48 Debugging Tools Programs that allow you to examine the state of another running program. Built in to the IDE in which you program Stop your program at a particular point (breakpoint) Inspect the contents of a variable ( (inspect or watch) Step through a program as it executes ( (step into, step over, step out).

Debugging Tools Typical debugging session Set a breakpoint in your code just prior to where you think a problem is occurring (i.e. on the line just ahead of the one in an exception s stack trace). Run the program in debug mode, and the program will stop just ahead of the crash 49 Debugging Tools Typical debugging session Set a breakpoint in your code just prior to where you think a problem is occurring (i.e. on the line just ahead of the one in an exception s stack trace). A breakpoint set at line 80. Run the program in debug mode, and the program will stop just ahead of the crash 50

Debugging Tools Typical debugging session Examine the variables at that point to determine what may have gone wrong. Use the watch or inspect features. Step forward through the program to examine how the state of objects change as the program is executing line-by-line. 51 Debugging Tools Typical debugging session 52 Examine the variables at that point to determine what may have gone wrong. Use the watch or inspect features. Step forward through the program to examine how the state of objects change The watch window as the displays program is executing the names and values of line-by-line. the local variables in the function

Debugging Tools Typical debugging session Step into if on a line with a function call, starts debugging that function, otherwise just executes the next line Step over if on a line with a function call, calls the function (but doesn t debug it), otherwise just executes the next line. 53 Debugging Tools Typical debugging session Step out runs the current function to completion, resumes debugging at the point at which the function was called. Continue runs to the next breakpoint. 54

Debugging Tools Typical debugging session Step into Step out Step out runs the current function to completion, resumes debugging at the point at which the function was called. Continue Continue runs to the next breakpoint. Step over 55 Debugging Tools Firebug demonstration http://encytemedia.com/blog/articles/2006/05/12/a n-in-depth-look-at-the-future-of-javascript- debugging-with-firebug http://www.digitalmediaminute.com/screencast/fire bug-js/ 56

Questions? 57 Last class! Final exam! Next Week 58

ITEC 136 Business Programming Concepts Week 14, Part 06 Self Quiz 59 Self Quiz What is the difference between validation and verification? Name the five different types of testing in the SDLC. Compare and contrast black-box box and white-box testing. 60

Self Quiz What is the advantage of a unit testing framework over some ad-hoc approach? Write a function issorted issorted that returns true if the array given as a parameter is sorted, and false otherwise. 61 Self Quiz Write a thorough set of test cases for issorted. Describe the process of debugging using a debugger. Describe the process of debugging using a logging facility. 62

ITEC 136 Business Programming Concepts Week 14, Part 07 Upcoming deadlines 63 Upcoming Deadlines Due April 13 Homework 12 (optional) Lab 4 Reflection paper Final exam 64