Coverage tools Eclipse Debugger Object-oriented Design Principles. Oct 26, 2016 Sprenkle - CSCI209 1

Similar documents
Objec&ves. Review. So-ware Quality Metrics Sta&c Analysis Tools Refactoring for Extensibility

Review: SoBware Development

Objec&ves. Review. JUnit Coverage Collabora&on

Designing a Social Network Prep for Lab 10. March 26, 2018 Sprenkle - CSCI Why classes and objects? How do we create new data types?

Objec&ves. Tes&ng 11/8/16. by Frederick P. Brooks, Jr., 1986

Text UI. Data Store Ø Example of a backend to a real Could add a different user interface. Good judgment comes from experience

Objec&ves. Usability Project Discussion. May 9, 2016 Sprenkle - CSCI335 1

CSCI 325: Distributed Systems. Objec?ves. Professor Sprenkle. Course overview Overview of distributed systems Introduc?on to reading research papers

11/15/13. Objectives. Review. Our Screen Saver Dependencies. Our Screen Saver Dependencies. Project Deliverables Timeline TEAM FINAL PROJECT

Google App Engine 8/10/17. CS Cloud Compu5ng Systems--Summer II 2017

There s a Cloud in My Enterprise

IBM Cognos Open Mic Cognos Analytics 11 Part nd June, IBM Corporation

Lab 11: Pair Programming. Review: Pair Programming Roles

ISO/IEC20000 Overview and Cer2fica2on Approach

Review of Lab 9. Review Lab 9. Social Network Classes/Driver Data. Lab 10 Design

Best Prac*ces & Training Guide for Professional Development and Networking - June 2011-

HANDS ACROSS BORDERS. An International Workshop on. Alterna(ve Mechanisms to Establish and Govern Transboundary Conserva(on Ini(a(ves

Creating and Managing Clauses. Selectica, Inc. Selectica Contract Performance Management System

New features in Oracle 11g for PL/SQL code tuning.

General Framework of Electronic Voting and Implementation thereof at National Elections in Estonia

LPGPU. Low- Power Parallel Compu1ng on GPUs. Ben Juurlink. Technische Universität Berlin. EPoPPEA workshop

2014 Second Chance Act Planning and Implementa4on (P&I) Guide

ForeScout Extended Module for McAfee epolicy Orchestrator

OUR PANELISTS. Linda Morrison L&D Academy Administrator Travelex. Be+y Mills L&D Manager Centra Health. Ma+ Hart L&OD Resource Officer Metropolitan

Decentralised solutions for renewable energies and water in developing countries

Minimum Spanning Tree Union-Find Data Structure. Feb 28, 2018 CSCI211 - Sprenkle. Comcast wants to lay cable in a neighborhood. Neighborhood Layout

Safer internet evening. 11 February 2014

One View Watchlists Implementation Guide Release 9.2

Bridging the Gap Between Legacy & Standards. d-wise. Bill Qubeck, Life Sciences Director

ROI CASE STUDY MARKLOGIC CQ ROLL CALL

OPTIMISING MEMBER ENGAGEMENT

TAFTW (Take Aways for the Week) APT Quiz and Markov Overview. Comparing objects and tradeoffs. From Comparable to TreeMap/Sort

Adaptive QoS Control for Real-Time Systems

Liveness: The Readers / Writers Problem

When the cartel investigators come calling: Top ten do s, top ten don ts

IVI-1.2: Operating Procedures

Building Blocks of Research Process. Alan Monroe Chapter 2

DevOps Course Content

Installation Guide: cpanel Plugin

Plan For the Week. Solve problems by programming in Python. Compsci 101 Way-of-life. Vocabulary and Concepts

Cadac SoundGrid I/O. User Guide

Public Libraries and Access to Justice: #2. The Role of Public Libraries

Congressional Forecast. Brian Clifton, Michael Milazzo. The problem we are addressing is how the American public is not properly informed about

Thinking Like a Computer Scien4st About Ancient Roman Graffi4

Deadlock. deadlock analysis - primitive processes, parallel composition, avoidance

DETERMINING CAUSALITY IN OBESITY

-"Illegal aliens" LCSH saga is a long story, won t cover it all today (will not discuss, for example, the question of interference by Congress) just

The Changing Faces of Aid: Challenges in financing the SDGs

The 10- Year Framework of Programmes on Sustainable Consump=on & Produc=on. * An Intergovernmental mandate * Introduction

Product Description

Welcome to All Things Project and Portfolio Management Part 2

Chapter 8: Recursion

Private Sponsorship in Refugee Resettlement. February 2017

1-1. Copyright 2015 Pearson Education, Inc.

Lecture 8: Verification and Validation

MWONGOZO; THE CODE OF GOVERNANCE FOR STATE CORPORATIONS. CS Catherine Musakali

Lecture Series - MSG 141 Technical Architecture and Standards C2- Simula:on Interoperability (C2SIM)

Statement on Security & Auditability

JD Edwards EnterpriseOne Applications

Real-Time CORBA. Chenyang Lu CSE 520S

LMLIP Community Event 2013 Information Session

Hoboken Public Schools. PLTW Introduction to Computer Science Curriculum

NetZero Greenhouse Project

Contract Law WHAT IS A CONTRACT

A Call for a Migra7on Consensus

TNAU Weather so. Weather Database cum weather analysis so.ware

Estonian National Electoral Committee. E-Voting System. General Overview

This Addendum Number 1 to the above referenced IFB responds to a clarification question asked with the MST response.

Compsci 290.3, Spring 2017 Software Design and Implementation: Mobile Landon Cox Owen Astrachan

Coali&on Ba*le Management Language (C- BML) and C2SIM History and Development

Topics we will cover:

Records Reten+on Basics for ESDs Texas State Associa+on of Fire and Emergency Districts (SAFE-D) Annual Conference Galveston, TX February 24, 2018

Recommendations For Reddit Users Avideh Taalimanesh and Mohammad Aleagha Stanford University, December 2012

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Strengthen Stewardship With Electronic Giving

BaxEnergy GmbH ( BaxEnergy ) Software License and Services Agreement

TEMPO Mission Project July 23, Project Manager: Alan Little

How to be a Delegate to the 2016 Democra-c Na-onal Conven-on. An overview of Florida s 2016 Delegate Selec=on Process

Speech to SOLACE National Elections Conference 16 January 2014 Peter Wardle

Philips Lifeline. Ø Chenyang Lu 1

This Week on developerworks: Ruby, AIX, collaboration, BPM, Blogger API Episode date:

1099 Pro - Tax Year 2017

31) Feature Models and MDA for Product Lines

Integration Guide for ElectionsOnline and netforum

Achieving energy efficiency through behaviour change: what does it take?

HOW TO RUN AN ONLINE ELECTION

Online Ballots. Configuration and User Guide INTRODUCTION. Let Earnings Edge Assist You with Your Online Ballot CONTENTS

Ocean Observatories Ini/a/ve Facili/es Board The Ocean Observatories Ini/a/ve Facility Board (OOIFB) provides independent input and guidance

Lecture 7 Act and Rule Utilitarianism. Based on slides 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

AN INMATES GUIDE TO. Habeas Corpus. Includes the 11 things you must know about the habeas system

X.Org Development Discussion Continues. Related Topics: Related Articles. Daylife Publishers Log In. Blog Developers Publishers

Heather Zuber-Harshman Duncan School of Law/ Thomas Jefferson School of Law. The 2011 Applied Legal Storytelling Conference Saturday, July 9, 2011

M-Vote (Online Voting System)

Drafting New York Civil-Litigation Documents: Part VI The Answer

Dependability in Distributed Systems

State of Minnesota Department of Public Safety Bureau of Criminal Apprehension

CSCI211: Intro Objectives

UTAH LEGISLATIVE BILL WATCH

From Astronomy to Policy A Not En(rely Unexpected Journey

Voices of Immigrant and Muslim Young People

Transcription:

Objec&ves Coverage tools Eclipse Debugger Object-oriented Design Principles Ø Design in the Small Ø DRY Ø Single responsibility principle Ø Shy Ø Open-closed principle Oct 26, 2016 Sprenkle - CSCI209 1 Review What are points in our tes&ng con&nuum? Ø What are the tradeoffs? How can we use coverage criteria? What does coverage not guarantee? Oct 26, 2016 Sprenkle - CSCI209 2 1

Review: Tes&ng Con&nuum No testing Statement- Coverage Branch- Coverage Path- Coverage Exhaustive Testing Oct 26, 2016 Sprenkle - CSCI209 3 Review: Uses of Coverage Criteria Stopping rule à sufficient tes&ng Ø Avoid unnecessary, redundant tests Measure test quality Ø Dependability es&mate Ø Confidence in es&mate Specify test cases Ø Describe addi&onal test cases needed Oct 26, 2016 Sprenkle - CSCI209 4 2

Coverage Criteria Discussion Is it always possible for a test suite to cover all the statements in a given program? Ø No. Could be infeasible statements Unreachable code Legacy code Configura&on that is not on site Do we need the test suite to cover 100% of statements/branches to believe it is adequate? Ø 100% coverage does not mean correct program Ø But < 100% coverage does mean tes&ng inadequacy Oct 26, 2016 Sprenkle - CSCI209 5 True/False Quiz A program that passes all test cases in a test suite with 100% path coverage is bug-free. Ø False. Ø Examples: The test suite may cover a faulty path with data values that don t expose the fault. Ø Towards Exhaus&ve Tes&ng Errors of omission Ø Missing a whole if Oct 26, 2016 Sprenkle - CSCI209 6 3

Example examplemethod(int a) 1 int b=60; Oct 26, 2016 Test Suite: 3-7: a=3 4-6: a=30 3-6: a=6 4-7: a=9 But, error shows up with 3-7: a=0 4-7: a=10 Sprenkle - CSCI209 if( a < 7 ) true false 3 4 a += 2; a -= 10; 5 if( a > 10 ) true false 6 7 b *= 2; b /= a; 8 return b; 2 Could divide by 0 7 True/False Quiz When you add test cases to a test suite that covers all statements so that it covers all branches, the new test suite is more likely to be beier at exposing faults. Ø True. Ø You re adding test cases and covering new paths, which may have faults. Oct 26, 2016 Sprenkle - CSCI209 8 4

Which Test Suite Is Beier? Statementadequate Test Suite Branchadequate Test Suite Branch-adequate suite is not necessarily beier than Statement-adequate suite Ø Statement-adequate suite could cover buggy paths and include input value tests that Branch-adequate suite doesn t Oct 26, 2016 Sprenkle - CSCI209 9 Example examplemethod(int a) TS1 (Statement-Adequate): Ø a=0, 6 TS2 (Branch-Adequate): Ø a=3, 30 Statement-adequate will find fault but branchadequate won t Ø Covers the path that exposes the fault int b=60; if( a < 7 ) a *= 2; if( a > 10 ) b *= 2; b /= a; return b; Oct 26, 2016 Sprenkle - CSCI209 10 5

Sonware Tes&ng: When is Enough Enough? Need to decide when tested enough Ø Balance goals of releasing applica&on, high quality standards Can use program coverage as stopping rule Ø Also measure of confidence in test suite Ø Statement, Branch, Path and their tradeoffs Ø Use coverage tools to measure statement, branch coverage S&ll, need to use some other smarts besides program coverage for crea&ng test cases Oct 26, 2016 Sprenkle - CSCI209 11 COVERAGE TOOLS Oct 26, 2016 Sprenkle - CSCI209 12 6

Coverage Tools Coverage is used in prac&ce Don t need to figure out coverage manually Available tools to calculate coverage Ø Examples for Java programs: Cobertura, Clover, JCoverage, Emma Ø Measure statement, branch/condi&onal, method coverage Oct 26, 2016 Sprenkle - CSCI209 13 Eclipse Plugin: EclEmma for Coverage Eclipse can be extended through plugins Ø Provide addi&onal func&onality EclEmma Plugin Ø Records execu&ng program s (or JUnit test case s) coverage Ø Displays coverage graphically Directions for installation are on the pre-class slides. Oct 26, 2016 Sprenkle - CSCI209 14 7

Demonstra&on Execute test with coverage Oct 26, 2016 Sprenkle - CSCI209 15 Note: Coverage and Tes&ng Project You won t be able to leverage coverage for the tes&ng project Ø Even if you write code, it s not _my_ code. Challenge of test-driven development (TDD) Ø Common prac&ce in industry Oct 26, 2016 Sprenkle - CSCI209 16 8

ECLIPSE DEBUGGER DEMO Oct 26, 2016 Sprenkle - CSCI209 17 OBJECT-ORIENTED DESIGN PRINCIPLES Oct 26, 2016 Sprenkle - CSCI209 18 9

Designing Systems All systems change during their life cycle Ø Requirements change Ø Misunderstandings in requirements Code must be so+ Ø Flexible Ø Easy to change New or revised circumstances New contexts Oct 26, 2016 Sprenkle - CSCI209 19 Designing Systems All systems change during their life cycle Ques&ons to consider: Ø How can we create designs that are stable in the face of change? Ø How do we know if our designs aren t maintainable? Ø What can we do if our code isn t maintainable? Answers will help us Ø Design our own code Ø Understand others code Oct 26, 2016 Sprenkle - CSCI209 20 10

Designing for Change Example July 2010, Oracle released Java 6 update 21 Ø Generated java.dll replaced COMPANY_NAME=Sun Microsystems, Inc. with COMPANY_NAME=Oracle Corpora&on Change caused OutOfMemoryError during Eclipse launch Ø Eclipse versions 3.3-3.6 (widespread!) Ø Why? Eclipse uses the name in the DLL in startup (run&me parameters) on Windows Temporary Fix: Oracle changed name back Requires changes to all Eclipse versions Source: http://www.infoq.com/news/2010/07/eclipse-java-6u21 Oct 26, 2016 Sprenkle - CSCI209 21 Overview Best Prac&ces (DRY): Don t repeat yourself Single Responsibility Principle Shy Ø Avoid Coupling Tell, Don t Ask Open-closed principle Avoid code smells A lot of similar, related fundamental principles Oct 26, 2016 Sprenkle - CSCI209 22 11

Don t Repeat Yourself (DRY): Knowledge Representa&on Every piece of knowledge must have a single, unambiguous, and authoritative representation within a system IntuiDon: when need to change representa&on, make in only one place Requires planning Ø What data needed, how represented (e.g., type) Oct 26, 2016 Sprenkle - CSCI209 23 Single Responsibility Principle Oct 26, 2016 Sprenkle - CSCI209 24 12

Single Responsibility Principle (SRP) There should never be more than one reason for a class to change IntuiDon: Ø Each responsibility is an axis of change More than one reason to change Ø Responsibili&es become coupled Changing one may affect the other Code breaks in unexpected ways We ve talked about this idea in this class. Give an example of adhering to SRP. Oct 26, 2016 Sprenkle - CSCI209 25 Example interface Network { public void connect(); public void disconnect(); public void send(string s); public String receive(); } Reasonable interface But has two responsibili&es Ø Can you group the func&onality into two responsibili&es? Check: Ø Change for different reasons? Called from different parts of program? Oct 26, 2016 Sprenkle - CSCI209 26 13

Shy Code Won t reveal too much of itself Otherwise: get coupling Ø Sta&c, dynamic, domain, temporal Coupling isn t always bad What techniques have we discussed for how to keep our code shy? Oct 26, 2016 Sprenkle - CSCI209 27 Achieving Shy Code Private instance variables Ø Especially mutable fields How can you make any field immutable? Make classes public only when need to be public Ø i.e., accessible by other classesà part of API Geier methods shouldn t return private, mutable state/objects Ø Use clone() before returning Oct 26, 2016 Sprenkle - CSCI209 28 14

Sta&c Coupling Descrip&on: Code requires other code to compile Problem if you include more than you need Ø Example: poor use of inheritance Brings excess baggage Inheritance is reserved for is-a rela&onships Ø Base class should not include op&onal behavior Ø Not uses-a or has-a Solu&on: use composi1on or delega1on instead Oct 26, 2016 Sprenkle - CSCI209 29 Dynamic Coupling Descrip&on: Code uses other code at run&me Ø getorder().getcustomer(). getaddress().getstate() Why a problem: Relies on several objects/classes and their state Ø If others change, my code has to change Solu&on: Talk directly to code Oct 26, 2016 Sprenkle - CSCI209 30 15

Domain Coupling Descrip&on: Business rules, policies are embedded in code Why a problem: if change frequently, code has to change frequently Solu&on: put into another place (metadata) Ø Database, property file Ø Process the rules Oct 26, 2016 Sprenkle - CSCI209 31 Temporal Coupling Descrip&on: Dependencies on &me Ø Order that things occur Ø Occur at a certain &me Ø Occur by a certain &me Ø Occur at the same &me Solu&on: Write concurrent code Oct 26, 2016 Sprenkle - CSCI209 32 16

Tell, Don t Ask Think of methods as sending a message Method call: sends a request to do something Ø Don t ask about details Ø Black-box, encapsula&on, informa&on hiding Oct 26, 2016 Sprenkle - CSCI209 33 Open-Closed Principle Bertrand Meyer Ø Author of Object-Oriented So+ware Construc1on Founda&onal text of OO programming Principle: Software entities (classes, modules, methods, etc.) should be open for extension but closed for modification Design modules that never change aner completely implemented If requirements change, extend behavior by adding code Ø Don t change exis&ng code à won t create bugs! Oct 26, 2016 Sprenkle - CSCI209 34 17

Aiributes of Sonware that Adhere to OCP Open for Extension Ø Behavior of module can be extended Ø Make module behave in new and different ways Closed for Modifica&on Ø No one can make changes to module These attributes seem to be at odds with each other. How can we resolve them? Oct 26, 2016 Sprenkle - CSCI209 35 Using Abstrac&on Abstract base classes or interfaces Ø Fixed abstrac&on à API Ø Cannot be changed Derived classes: possible behaviors Ø Can always create new child classes of abstract base class Oct 26, 2016 Sprenkle - CSCI209 36 18

Not Open-Closed Principle Client uses Server class public class Client { public void method(server x) { } } Client Server Oct 26, 2016 Sprenkle - CSCI209 37 Open-Closed Principle Or ServerInterface Client uses AbstractServer class public class Client { public void method(abstractserver x) { } } Client Abstract Server Server extends Server2 Oct 26, 2016 Sprenkle - CSCI209 38 19

Strategic Closure No significant program can be completely closed Must choose kinds of changes to close Ø Requires knowledge of users, probability of changes Goal: Most probable changes should be closed Oct 26, 2016 Sprenkle - CSCI209 39 Heuris&cs and Conven&ons Member variables are private Ø A method that depends on a variable cannot be closed to changes to that variable Ø The class itself can t be closed to it Ø All other classes should be No global variables Ø Every module that depends on global variable cannot be closed to changes to that variable Ø What happens if someone uses variable in unexpected way? Ø Counter examples: System.out, System.in Apply abstraction to parts you think are going to change Oct 26, 2016 Sprenkle - CSCI209 40 20

TODO Project 1: Due tonight! Extra credit opportuni&es Oct 26, 2016 Sprenkle - CSCI209 41 21