Test-Driven Development

Size: px
Start display at page:

Download "Test-Driven Development"

Transcription

1 Test-Driven Development Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 27 12/2/08 University of Colorado, 2008

2 Credit where Credit is Due Some of the material for this lecture is taken from Test-Driven Development by Kent Beck as such some of this material is copyright Addison Wesley, 2003 In addition, some material for this lecture is taken from Agile Software Development: Principles, Patterns, and Practices by Robert C. Martin as such some materials is copyright Pearson Education, Inc.,

3 Goals for this lecture Introduce the concept of Test-Driven Development (TDD) Present several examples 3

4 Test-Driven Development The idea is simple No production code is written except to make a failing test pass Implication You have to write test cases before you write code 4

5 Writing Test Cases First This means that when you first write a test case, you may be testing code that does not exist And since that means the test case will not compile, obviously the test case fails After you write the skeleton code for the objects referenced in the test case, it will now compile, but also may not pass So, then you write the simplest code that will make the test case pass 5

6 Example (I) Consider writing a program to score the game of bowling You might start with the following test public class TestGame extends TestCase { public void testonethrow() { Game g = new Game(); g.addthrow(5); assertequals(5, g.getscore()); When you compile this program, the test fails because the Game class does not yet exist. But: You have defined two methods on the class that you want to use You are designing this class from a client s perspective 6

7 Example (II) You would now write the Game class public class Game { public void addthrow(int pins) { public int getscore() { return 0; The code now compiles but the test will still fail: getscore() returns 0 not 5 In Test-Driven Design, Beck recommends taking small, simple steps So, we get the test case to compile before we get it to pass 7

8 Example (III) Once we confirm that the test still fails, we would then write the simplest code to make the test case pass; that would be public class Game { public void addthrow(int pins) { public int getscore() { return 5; The test case now passes! 8

9 Example (IV) But, this code is not very useful! Lets add a new test case to enable progress public class TestGame extends TestCase { public void testonethrow() { Game g = new Game(); g.addthrow(5); assertequals(5, g.getscore()); public void testtwothrows() { Game g = new Game() g.addthrow(5) g.addthrow(4) assertequals(9, g.getscore()); The first test passes, but the second case fails (since 9 5) This code is written using JUnit; it uses reflection to invoke tests automatically 9

10 Example (V) We have duplication of information between the first test and the Game class In particular, the number 5 appears in both places This duplication occurred because we were writing the simplest code to make the test pass Now, in the presence of the second test case, this duplication does more harm than good So, we must now refactor the code to remove this duplication 10

11 Example (VI) public class Game { private int score = 0; public void addthrow(int pins) { score += pins; public int getscore() { return score; Both tests now pass. Progress! 11

12 Example (VII) But now we to make additional progress, we add another test case to the TestGame class public void testsimplespare() { Game g = new Game() g.addthrow(3); g.addthrow(7); g.addthrow(3); assertequals(13, g.scoreforframe(1)); assertequals(16, g.getscore()); We re back to the code not compiling due to scoreforframe() We ll need to add a method body for this method and give it the simplest implementation that will make all three of our tests cases pass 12

13 TDD Life Cycle The life cycle of test-driven development is Quickly add a test Run all tests and see the new one fail Make a simple change Run all tests and see them all pass Refactor to remove duplication This cycle is followed until you have met your goal; note that this cycle simply adds testing to the add functionality; refactor loop covered in the last two lectures 13

14 TDD Life Cycle, continued Kent Beck likes to perform TDD using a testing framework, such as JUnit. Within such frameworks failing tests are indicated with a red bar passing tests are shown with a green bar As such, the TDD life cycle is sometimes described as red bar/green bar/refactor 14

15 JUnit: Red Bar... When a test fails: You see a red bar Failures/Errors are listed Clicking on a failure displays more detailed information about what went wrong 15

16 Example Background: Multi-Currency Money Lets design a system that will allow us to perform financial transactions with money that may be in different currencies e.g. if we know that the exchange rate from Swiss Francs to U.S. Dollars is 2 to 1 then we can calculate expressions like or 5 USD + 10 CHF = 10 USD 5 USD + 10 CHF = 20 CHF 16

17 Starting From Scratch Lets start developing such an example How do we start? TDD recommends writing a list of things we want to test This list can take any format, just keep it simple Example $ CHF = $10 if rate is 2:1 $5 * 2 = $10 17

18 First Test The first test case looks a bit complex, lets start with the second 5 USD * 2 = 10 USD First, we write a test case public void testmultiplication() { Dollar five = new Dollar(5); five.times(2); assertequals(10, five.amount) 18

19 Discussion on Test Case public void testmultiplication() { Dollar five = new Dollar(5); five.times(2); assertequals(10, five.amount) What benefits does this provide? target class plus some of its interface we are designing the interface of the Dollar class by thinking about how we would want to use it We have made a testable assertion about the state of that class after we perform a particular sequence of operations 19

20 What s Next? We need to update our test list The test case revealed some things about Dollar that we will want to address We are representing the amount as an integer, which will make it difficult to represent values like 1.5 USD; how will we handle rounding of factional amounts? Dollar.amount is public; violates encapsulation What about side effects?; we first declared our variable as five but after we performed the multiplication it now equals ten 20

21 Update Testing List The New List 5 USD + 10 CHF = 10 USD $5 * 2 = $10 make amount private Dollar side-effects? Money rounding? Now, we need to fix the compile errors no class Dollar, no constructor, no method: times(), no field: amount 21

22 First version of Dollar Class public class Dollar { public Dollar(int amount) { public void times(int multiplier) { public int amount; Now our test compiles and fails! 22

23 Too Slow? Note: we did the simplest thing to make the test compile; now, we are going to do the simplest thing to make the test pass Is this process too slow? Yes, as you get familiar with the TDD life cycle you will gain confidence and make bigger steps No, taking small simple steps avoids mistakes; beginning programmers try to code too much before invoking the compiler; they then spend the rest of their time debugging! 23

24 How do we make the test pass? Here s one way public void times(int multiplier) { amount = 5 * 2; The test now passes, we received a green bar! Now, we need to refactor to remove duplication But where is the duplication? Hint: its between the Dollar class and the test case 24

25 Refactoring To remove the duplication of the test data and the hard-wired code of the times method, we think the following We are trying to get a 10 at the end of our test case and we ve been given a 5 in the constructor and a 2 was passed as a parameter to the times method So, lets connect the dots 25

26 First version of Dollar Class public class Dollar { public Dollar(int amount) { this.amount = amount; public void times(int multiplier) { amount = amount * multiplier; public int amount; Now our test compiles and passes, and we didn t have to cheat! 26

27 One loop complete! Before writing the next test case, we update our testing list 5 USD + 10 CHF = 10 USD $5 * 2 = $10 make amount private Dollar side-effects? Money rounding? 27

28 One more example Lets address the Dollar Side-Effects item and then move on to general lessons So, lets write the next test case When we called the times operation our variable five was pointing at an object whose amount equaled ten ; not good the times operation had a side effect which was to change the value of a previously created value object Think about it, as much as you might like to, you can t change a 5 dollar bill into a 500 dollar bill; the 5 dollar bill remains the same throughout multiple financial transactions 28

29 Next test case The behavior we want is public void testmultiplication() { Dollar five = new Dollar(5); Dollar product = five.times(2); assertequals(10, product.amount); product = five.times(3); assertequals(15, product.amount); assertequals(5, five.amount); 29

30 Test fails The test fails because it won t compile; We need to change the signature of the times method; previously it returned void and now it needs to return Dollar public Dollar times(int multiplier) { amount = amount * multiplier; return null; The test compiles but still fails; as Kent Beck likes to say Progress! 30

31 Test Passes To make the test pass, we need to return a new Dollar object whose amount equals the result of the multiplication public Dollar times(int multiplier) { return new Dollar(amount * multiplier); Test Passes; Cross Dollar Side Effects? off the testing list; second loop complete! There was no need to refactor in this situation 31

32 Discussion of the Example There is still a long way to go But only scratched the surface we saw the life cycle performed twice we saw the advantage of writing tests first we saw the advantage of keeping things simple we saw the advantage of keeping a testing list to keep track of our progress Plus, as we write new code, we will know if we are breaking things because our old test cases will fail if we do; if the old tests stay green, we can proceed with confidence 32

33 Principles of TDD Testing List keep a record of where you want to go; Test First Beck keeps two lists, one for his current coding session and one for later ; You won t necessarily finish everything in one go! Write tests before code, because you probably won t do it after Writing test cases gets you thinking about the design of your implementation; does this code structure make sense? what should the signature of this method be? 33

34 Principles of TDD, continued Assert First How do you write a test case? By writing its assertions first! Suppose you are writing a client/server system and you want to test an interaction between the server and the client Suppose that for each transaction some string has to have been read from the server, and the socket used to talk to the server should be closed after the transaction Lets write the test case 34

35 Assert First public void testcompletetransaction { asserttrue(reader.isclosed()); assertequals( abc, reply.contents()); Now write the code that will make these asserts possible 35

36 Assert First, continued public void testcompletetransaction { Server writer = Server(defaultPort(), abc ) Socket reader = Socket( localhost, defaultport()); Buffer reply = reader.contents(); asserttrue(reader.isclosed()); assertequals( abc, reply.contents()); Now you have a test case that can drive development if you don t like the interface above for server and socket, then write a different test case or refactor the test case, after you get the above test to pass 36

37 Principles of TDD, continued Evident Data How do you represent the intent of your test data Even in test cases, we d like to avoid magic numbers; consider this rewrite of our second times test case public void testmultiplication() { Dollar five = new Dollar(5); Dollar product = five.times(2); assertequals(5 * 2, product.amount); product = five.times(3); assertequals(5 * 3, product.amount); Replace the magic numbers with expressions 37

38 Summary Test-Driven Design is a mini software development life cycle that helps to organize coding sessions and make them more productive Write a failing test case Make the simplest change to make it pass Refactor to remove duplication Repeat! 38

39 Reflections Test-Driven Design builds on the practices of Agile Design Methods If you decide to adopt it, not only do you write code only to make failing tests pass but you also get an easy way to integrate refactoring into your daily coding practices an easy way to introduce integration testing/building your system every day into your work environment because you need to run all your tests to make sure that your new code didn t break anything; this has the side effect of making refactoring safe courage to try new things, such as unfamiliar design pattern, because now you have a safety net 39

40 Ken s Corner: Testing Frameworks JUnit Tutorial: < PyUnit: < Unit testing in Objective-C and Xcode: < unittestingwithxcode3.html> Unit testing with C#: < Unit testing for Ruby: < Unit.html> 40

41 Coming Up Next Lecture 28: Additional UML Models; Grasp Intro Lecture 29: Grasp Lecture 30: Concurrency in OO Systems NOTE: This schedule is tentative and may change! NEED VOLUNTEER: We will administer FCQs for this class at the end of lecture on Thursday 41

Credit where Credit is Due. Lecture 29: Test-Driven Development. Test-Driven Development. Goals for this lecture

Credit where Credit is Due. Lecture 29: Test-Driven Development. Test-Driven Development. Goals for this lecture Lecture 29: Test-Driven Development Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Credit where Credit is Due Some of the material for this lecture is taken from

More information

Test-Driven Development

Test-Driven Development Test-Driven Development Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 28 04/21/11 University of Colorado, 2011 Credit where Credit is Due Some of the material for this lecture

More information

Test-Driven Development

Test-Driven Development Foundations of Software Engineering Test-Driven Development Fall 2016 Department of Computer Science Ben-Gurion university Based on Presentation by Nurit Gal-oz, Department of Computer Science Ben-Gurion

More information

Refactoring, Part 2. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09. University of Colorado, 2009

Refactoring, Part 2. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09. University of Colorado, 2009 Refactoring, Part 2 Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09 University of Colorado, 2009 1 Introduction Credit where Credit is Due Some of the material for

More information

Conduite de Projet Cours 9 Test-Driven Development

Conduite de Projet Cours 9 Test-Driven Development Conduite de Projet Cours 9 Test-Driven Development Stefano Zacchiroli zack@irif.fr Laboratoire IRIF, Université Paris Diderot 2017 2018 URL https://upsilon.cc/zack/teaching/1718/cproj/ Copyright 2013 2018

More information

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle Boggle If you are not familiar with the game Boggle, the game is played with 16 dice that have letters on all faces. The dice are randomly deposited into a four-by-four grid so that the players see the

More information

Test First Software Development

Test First Software Development Test First Software Development Jacob Kristhammar Roger Schildmeijer D04, Lund Institute of Technology, Sweden {d04jk d04rp}@student.lth.se 2008-02-06 Abstract In this in-depth study we will try to explain

More information

Dealing with Bugs. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 27 04/21/2009

Dealing with Bugs. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 27 04/21/2009 Dealing with Bugs Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 27 04/21/2009 University of Colorado, 2009 1 Goals 2 Review material from Chapter 11 of Pilone & Miles Dealing with

More information

Practical Objects: Test Driven Software Development using JUnit

Practical Objects: Test Driven Software Development using JUnit 1999 McBreen.Consulting Practical Objects Test Driven Software Development using JUnit Pete McBreen, McBreen.Consulting petemcbreen@acm.org Test Driven Software Development??? The Unified Process is Use

More information

TEST-DRIVEN DEVELOPMENT

TEST-DRIVEN DEVELOPMENT tdd 2003/6/10 21:42 page 5 #25 Chapter 1 TEST-DRIVEN DEVELOPMENT To vouch this, is no proof, Without more wider and more overt test -Othello,Act 1 Scene 3 William Shakespeare From programmers to users,

More information

Intermediate Cucumber. CSCI 5828: Foundations of Software Engineering Lecture 17 03/13/2012

Intermediate Cucumber. CSCI 5828: Foundations of Software Engineering Lecture 17 03/13/2012 Intermediate Cucumber CSCI 5828: Foundations of Software Engineering Lecture 17 03/13/2012 1 ReadyTalk Recruiting Event The ACM Student Chapter is hosting a recruiting event by a local Denver start-up

More information

Basic Keywords Practice Session

Basic Keywords Practice Session Basic Keywords Practice Session Introduction In this article from my free Java 8 course, we will apply what we learned in my Java 8 Course Introduction to our first real Java program. If you haven t yet,

More information

Test-Driven Development (TDD)

Test-Driven Development (TDD) Test-Driven Development (TDD) CS 4501 / 6501 Software Testing [Lasse Koskela, Test Driven, Chapters 2-3] 1 Agile Airplane Testing Test harness: Appearance matches Color coding in place Fly 6ft (or 2m)

More information

Credit where Credit is Due. Lecture 25: Refactoring. Goals for this lecture. Last Lecture

Credit where Credit is Due. Lecture 25: Refactoring. Goals for this lecture. Last Lecture Credit where Credit is Due Lecture 25: Refactoring Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2002 Some of the material for this lecture and lecture 26 is taken

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation Outline Problem: Create, read in and print out four sets of student grades Setting up the problem Breaking

More information

Introduction to Extreme Programming

Introduction to Extreme Programming Introduction to Extreme Programming References: William Wake, Capital One Steve Metsker, Capital One Kent Beck Robert Martin, Object Mentor Ron Jeffries,et.al. 12/3/2003 Slide Content by Wake/Metsker 1

More information

Stage 11 Array Practice With. Zip Code Encoding

Stage 11 Array Practice With. Zip Code Encoding A Review of Strings You should now be proficient at using strings, but, as usual, there are a few more details you should know. First, remember these facts about strings: Array Practice With Strings are

More information

COURSE 11 DESIGN PATTERNS

COURSE 11 DESIGN PATTERNS COURSE 11 DESIGN PATTERNS PREVIOUS COURSE J2EE Design Patterns CURRENT COURSE Refactoring Way refactoring Some refactoring examples SOFTWARE EVOLUTION Problem: You need to modify existing code extend/adapt/correct/

More information

Test Driven Development TDD

Test Driven Development TDD Test Driven Development TDD Testing Testing can never demonstrate the absence of errors in software, only their presence Edsger W. Dijkstra (but it is very good at the latter). Testing If it's worth building,

More information

COMP 354 TDD and Refactoring

COMP 354 TDD and Refactoring COMP 354 TDD and Refactoring Greg Butler Office: EV 3.219 Computer Science and Software Engineering Concordia University, Montreal, Canada Email: gregb@cs.concordia.ca Winter 2015 Course Web Site: http://users.encs.concordia.ca/

More information

Object Fundamentals, Part One. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009

Object Fundamentals, Part One. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009 Object Fundamentals, Part One Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009 1 Lecture Goals Introduce basic concepts, terminology, and notations for object-oriented

More information

Object Fundamentals. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 2 08/30/2007

Object Fundamentals. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 2 08/30/2007 Object Fundamentals Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 2 08/30/2007 1 Lecture Goals Introduce basic concepts, terminology, and notations for object-oriented analysis,

More information

Object Oriented Software Design - I

Object Oriented Software Design - I Object Oriented Software Design - I Unit Testing Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa November 28, 2011 G. Lipari (Scuola Superiore Sant Anna) Unit Testing November

More information

Test Driven Development (TDD)

Test Driven Development (TDD) Test Driven Development (TDD) Test Driven Development Introduction Good programmers write code, great programmers write tests Never, in the field of programming, have so many owed so much to so few - Martin

More information

Outline. Logistics. Logistics. Principles of Software (CSCI 2600) Spring Logistics csci2600/

Outline. Logistics. Logistics. Principles of Software (CSCI 2600) Spring Logistics  csci2600/ Outline Principles of Software (CSCI 600) Spring 018 http://www.cs.rpi.edu/academics/courses/spring18/csci600/ Konstantin Kuzmin, kuzmik@cs.rpi.edu Office hours: Monday and Thursday 4:00 pm - 5:30 pm Mailing

More information

print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically

print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically JUnit testing Current practice print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically undergoes many changes over

More information

CS1004: Intro to CS in Java, Spring 2005

CS1004: Intro to CS in Java, Spring 2005 CS1004: Intro to CS in Java, Spring 2005 Lecture #13: Java OO cont d. Janak J Parekh janak@cs.columbia.edu Administrivia Homework due next week Problem #2 revisited Constructors, revisited Remember: a

More information

CIS 121 Data Structures and Algorithms with Java Spring 2018

CIS 121 Data Structures and Algorithms with Java Spring 2018 CIS 121 Data Structures and Algorithms with Java Spring 2018 Homework 2 Thursday, January 18 Due Monday, January 29 by 11:59 PM 7 Required Problems (85 points), and Style and Tests (15 points) DO NOT modify

More information

Software Design and Analysis CSCI 2040

Software Design and Analysis CSCI 2040 Software Design and Analysis CSCI 2040 Introduce two important development practices in the context of the case studies: Test-Driven Development Refactoring 2 Logic is the art of going wrong with confidence

More information

Java Review via Test Driven Development

Java Review via Test Driven Development Java Review via Test Driven Development By Rick Mercer with help from Kent Beck and Scott Ambler 2-1 Outline What is TDD? Tests as documentation Tests as a way to verify your code works 2-2 Test Driven

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

CS201 - Assignment 3, Part 1 Due: Friday February 28, at the beginning of class

CS201 - Assignment 3, Part 1 Due: Friday February 28, at the beginning of class CS201 - Assignment 3, Part 1 Due: Friday February 28, at the beginning of class One of the keys to writing good code is testing your code. This assignment is going to introduce you and get you setup to

More information

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson More on Design CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson Outline Additional Design-Related Topics Design Patterns Singleton Strategy Model View Controller Design by

More information

Assertions, pre/postconditions

Assertions, pre/postconditions Programming as a contract Assertions, pre/postconditions Assertions: Section 4.2 in Savitch (p. 239) Specifying what each method does q Specify it in a comment before method's header Precondition q What

More information

Agile Architecture. The Why, the What and the How

Agile Architecture. The Why, the What and the How Agile Architecture The Why, the What and the How Copyright Net Objectives, Inc. All Rights Reserved 2 Product Portfolio Management Product Management Lean for Executives SAFe for Executives Scaled Agile

More information

Unit Testing with JUnit and CppUnit

Unit Testing with JUnit and CppUnit Unit Testing with JUnit and CppUnit Software Testing Fundamentals (1) What is software testing? The process of operating a system or component under specified conditions, observing or recording the results,

More information

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) CSE 11 Winter 2017 Program Assignment #2 (100 points) START EARLY! Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) PROGRAM #2: DoubleArray11 READ THE ENTIRE ASSIGNMENT BEFORE STARTING In lecture,

More information

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics Inf1-OOP OOP Exam Review Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics March 16, 2015 Overview Overview of examinable material: Lectures Topics S&W sections Week 1 Compilation,

More information

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm) CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, 2017 11:30pm) This assignment focuses on recursive backtracking. Turn in the following files using the link on the course

More information

Introduction to Extreme Programming. Extreme Programming is... Benefits. References: William Wake, Capital One Steve Metsker, Capital One Kent Beck

Introduction to Extreme Programming. Extreme Programming is... Benefits. References: William Wake, Capital One Steve Metsker, Capital One Kent Beck Introduction to Extreme Programming References: William Wake, Capital One Steve Metsker, Capital One Kent Beck Extreme Programming is... Lightweight software development method used for small to medium-sized

More information

Soda Machine Laboratory

Soda Machine Laboratory Soda Machine Laboratory Introduction This laboratory is intended to give you experience working with multiple queue structures in a familiar real-world setting. The given application models a soda machine

More information

E xtr B e y CS R m oy 6704, e T a P n a Spring r n o d J g ia n 2002 r g a S m hu m ing

E xtr B e y CS R m oy 6704, e T a P n a Spring r n o d J g ia n 2002 r g a S m hu m ing Extreme Programming CS 6704, Spring 2002 By Roy Tan and Jiang Shu Contents What is Extreme Programming (XP)? When to use XP? Do we need yet another software methodology? XP s rules and practices XP s relation

More information

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

Overview. State-of-the-Art. Relative cost of error correction. CS 619 Introduction to OO Design and Development. Testing. Overview CS 619 Introduction to OO Design and Development ing! Preliminaries! All sorts of test techniques! Comparison of test techniques! Software reliability Fall 2012! Main issues: There are a great

More information

Object Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009

Object Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009 Object Fundamentals Part Two Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations

More information

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy Testing ENGI 5895: Software Design Andrew Vardy Faculty of Engineering & Applied Science Memorial University of Newfoundland March 6, 2017 Outline 1 Levels of Testing 2 Testing Methods 3 Test Driven Development

More information

A few more things about Agile and SE. Could help in interviews, but don t try to bluff your way through

A few more things about Agile and SE. Could help in interviews, but don t try to bluff your way through A few more things about Agile and SE Could help in interviews, but don t try to bluff your way through 1 Refactoring How to do it, where it fits in http://www.cse.ohio-state.edu/~crawfis/cse3902/index.htm

More information

Introduction to Test Driven Development (To be used throughout the course)

Introduction to Test Driven Development (To be used throughout the course) Introduction to Test Driven Development (To be used throughout the course) Building tests and code for a software radio Concepts Stages in a conventional radio Stages in a software radio Goals for the

More information

Test automation / JUnit. Building automatically repeatable test suites

Test automation / JUnit. Building automatically repeatable test suites Test automation / JUnit Building automatically repeatable test suites JUnit in Eclipse For this course, we will use JUnit in Eclipse It is automatically a part of Eclipse One documentation site (all one

More information

Analysis of the Test Driven Development by Example

Analysis of the Test Driven Development by Example Computer Science and Applications 1 (2013) 5-13 Aleksandar Bulajic and Radoslav Stojic The Faculty of Information Technology, Metropolitan University, Belgrade, 11000, Serbia Received: June 18, 2013 /

More information

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy Testing ENGI 5895: Software Design Andrew Vardy Faculty of Engineering & Applied Science Memorial University of Newfoundland March 6, 2017 Outline 1 Levels of Testing 2 Testing Methods 3 Test Driven Development

More information

Credit is where Credit is Due. Lecture 28: OO Design Heuristics (Part 2) This Lecture. Last Lecture: OO Heuristics. Rules of Thumb

Credit is where Credit is Due. Lecture 28: OO Design Heuristics (Part 2) This Lecture. Last Lecture: OO Heuristics. Rules of Thumb Credit is where Credit is Due Lecture 28: OO Design Heuristics (Part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2002 Some material for this lecture is taken

More information

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 3

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 3 COMP 111 Introduction to Computer Science and Object-Oriented Programming Tasks and Tools download submit edit Web-CAT compile unit test view results Working with Java Classes You Use You Complete public

More information

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics Inf1-OP Inf1-OP Exam Review Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 20, 2017 Overview Overview of examinable material: Lectures Week 1

More information

Lab Exercise Test First using JUnit

Lab Exercise Test First using JUnit Lunds tekniska högskola Datavetenskap, Nov, 2017 Görel Hedin/Ulf Asklund EDAF45 Programvaruutveckling i grupp projekt Lab Exercise Test First using JUnit Goal This lab is intended to demonstrate basic

More information

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes 1 CS257 Computer Science II Kevin Sahr, PhD Lecture 5: Writing Object Classes Object Class 2 objects are the basic building blocks of programs in Object Oriented Programming (OOP) languages objects consist

More information

Aggregation. Introduction to Computer Science I. Overview (1): Overview (2): CSE 1020 Summer Bill Kapralos. Bill Kapralos.

Aggregation. Introduction to Computer Science I. Overview (1): Overview (2): CSE 1020 Summer Bill Kapralos. Bill Kapralos. Aggregation Thursday, July 6 2006 CSE 1020, Summer 2006, Overview (1): Before We Begin Some administrative details Some questions to consider Aggregation Overview / Introduction The aggregate s constructor

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Lecture 04 Software Test Automation: JUnit as an example

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 15 Testing Where we are Some very basic software engineering topics in the midst of tools Today: testing (how, why, some terms) Later:

More information

Anatomy of a Class Encapsulation Anatomy of a Method

Anatomy of a Class Encapsulation Anatomy of a Method Writing Classes Writing Classes We've been using predefined classes. Now we will learn to write our own classes to define objects Chapter 4 focuses on: class definitions instance data encapsulation and

More information

Software Engineering. Top-Down Design. Bottom-Up Design. Software Process. Top-Down vs. Bottom-Up 15/06/2011

Software Engineering. Top-Down Design. Bottom-Up Design. Software Process. Top-Down vs. Bottom-Up 15/06/2011 CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2011 Thorsten Joachims Lecture 7: Software Design Software Engineering The art by which we start with a problem statement and gradually

More information

CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 187: Programming with Data Structures Spring 2015 CmpSci 187: Programming with Data Structures Spring 2015 Lecture #13, Concurrency, Interference, and Synchronization John Ridgway March 12, 2015 Concurrency and Threads Computers are capable of doing more

More information

Learning from Bad Examples. CSCI 5828: Foundations of Software Engineering Lecture 25 11/18/2014

Learning from Bad Examples. CSCI 5828: Foundations of Software Engineering Lecture 25 11/18/2014 Learning from Bad Examples CSCI 5828: Foundations of Software Engineering Lecture 25 11/18/2014 1 Goals Demonstrate techniques to design for shared mutability Build on an example where multiple threads

More information

EVALUATION COPY. Test-Driven Development Using NUnit and C# Student Guide Revision 4.6. Unauthorized reproduction or distribution is prohibited.

EVALUATION COPY. Test-Driven Development Using NUnit and C# Student Guide Revision 4.6. Unauthorized reproduction or distribution is prohibited. Test-Driven Development Using NUnit and C# Student Guide Revision 4.6 Object Innovations Course 4105 Test-Driven Development Using NUnit and C# Rev. 4.6 Student Guide Information in this document is subject

More information

EECS 4313 Software Engineering Testing

EECS 4313 Software Engineering Testing EECS 4313 Software Engineering Testing Topic 03: Test automation / JUnit - Building automatically repeatable test suites Zhen Ming (Jack) Jiang Acknowledgement Some slides are from Prof. Alex Orso Relevant

More information

J2EE AntiPatterns. Bill Dudney. Object Systems Group Copyright 2003, Object Systems Group

J2EE AntiPatterns. Bill Dudney. Object Systems Group Copyright 2003, Object Systems Group J2EE AntiPatterns Bill Dudney Object Systems Group bill@dudney.net Bill Dudney J2EE AntiPatterns Page 1 Agenda What is an AntiPattern? What is a Refactoring? AntiPatterns & Refactorings Persistence Service

More information

Relaxed Memory-Consistency Models

Relaxed Memory-Consistency Models Relaxed Memory-Consistency Models Review. Why are relaxed memory-consistency models needed? How do relaxed MC models require programs to be changed? The safety net between operations whose order needs

More information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 4 C Pointers 2004-09-08 Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Cal flies over Air Force We re ranked 13 th in the US and

More information

Lesson 13 - Vectors Dynamic Data Storage

Lesson 13 - Vectors Dynamic Data Storage Lesson 13 - Vectors Dynamic Data Storage Summary In this lesson we introduce the Standard Template Library by demonstrating the use of Vectors to provide dynamic storage of data elements. New Concepts

More information

Testing and Debugging

Testing and Debugging Testing and Debugging Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up From Last Lecture: - What are the expected operations for a map ADT? - How would you implement a Map - To optimize

More information

Introduction to JUnit. Data Structures and Algorithms for Language Processing

Introduction to JUnit. Data Structures and Algorithms for Language Processing Data Structures and Algorithms for Language Processing What is JUnit JUnit is a small, but powerful Java framework to create and execute automatic unit tests Unit testing is the test of a part of a program

More information

Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

More information

xtreme Programming (summary of Kent Beck s XP book) Stefan Resmerita, WS2015

xtreme Programming (summary of Kent Beck s XP book) Stefan Resmerita, WS2015 xtreme Programming (summary of Kent Beck s XP book) 1 Contents The software development problem The XP solution The JUnit testing framework 2 The Software Development Problem 3 Risk Examples delivery schedule

More information

Unit Testing as Hypothesis Testing

Unit Testing as Hypothesis Testing Unit Testing as Hypothesis Testing Jonathan Clark September 19, 2012 5 minutes You should test your code. Why? To find bugs. Even for seasoned programmers, bugs are an inevitable reality. Today, we ll

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

XC Total Max Score Grader

XC Total Max Score Grader NAME: NETID: CS2110 Fall 2013, Prelim 1 Thursday Oct 10, 2013 (7:30-9:00p) The exam is closed book and closed notes. Do not begin until instructed. You have 90 minutes. Good luck! Write your name and Cornell

More information

BM214E Object Oriented Programming Lecture 4

BM214E Object Oriented Programming Lecture 4 BM214E Object Oriented Programming Lecture 4 Computer Numbers Integers (byte, short, int, long) whole numbers exact relatively limited in magnitude (~10 19 ) Floating Point (float, double) fractional often

More information

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University (12-1) OOP: Polymorphism in C++ D & D Chapter 12 Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University Key Concepts Polymorphism virtual functions Virtual function tables

More information

Programmieren II. Unit Testing & Test-Driven Development. Alexander Fraser.

Programmieren II. Unit Testing & Test-Driven Development. Alexander Fraser. Programmieren II Unit Testing & Test-Driven Development Alexander Fraser fraser@cl.uni-heidelberg.de (Based on material from Lars Vogel and T. Bögel) July 2, 2014 1 / 62 Outline 1 Recap 2 Testing - Introduction

More information

CS159. Nathan Sprague. September 30, 2015

CS159. Nathan Sprague. September 30, 2015 CS159 Nathan Sprague September 30, 2015 Testing Happens at Multiple Levels Unit Testing - Test individual classes in isolation. Focus is on making sure that each method works according to specification.

More information

Test Driven Development. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Tobias Pulls and Eivind Nordby

Test Driven Development. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Tobias Pulls and Eivind Nordby Test Driven Development Faculty of Economic Sciences, Communication and IT 2010-09-03 Tobias Pulls and Principle Use Executable Specifications Test Driven Development (TDD) xunit Behaviour Driven Development

More information

3. Simple Types, Variables, and Constants

3. Simple Types, Variables, and Constants 3. Simple Types, Variables, and Constants This section of the lectures will look at simple containers in which you can storing single values in the programming language C++. You might find it interesting

More information

An Improved Java Programming Learning System Using Test-Driven Development Method

An Improved Java Programming Learning System Using Test-Driven Development Method An Improved Java Programming Learning System Using Test-Driven Development Method Nobuo Funabiki, Yuuki Fukuyama, Yukiko Matsushima, Toru Nakanishi, Kan Watanabe Abstract To enhance educational effects

More information

Lecture 15 Software Testing

Lecture 15 Software Testing Lecture 15 Software Testing Includes slides from the companion website for Sommerville, Software Engineering, 10/e. Pearson Higher Education, 2016. All rights reserved. Used with permission. Topics covered

More information

CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, :30pm)

CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, :30pm) CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, 2015 11:30pm) This program focuses on binary trees and recursion. Turn in the following files using the link on the

More information

B. What strategy (order of refactorings) would you use to improve the code?

B. What strategy (order of refactorings) would you use to improve the code? { return title.gettext(); public boolean needssplit() { return costlabel.gettext().equals(" >3 "); public boolean needsestimate() { return costlabel.gettext().equals("? "); Challenges PG-1. Smells. A.

More information

Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at

Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at JUnit Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at the moment), or You can build a test suite (a thorough

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

CS168 Programming Assignment 2: IP over UDP

CS168 Programming Assignment 2: IP over UDP Programming Assignment 2: Assignment Out: February 17, 2011 Milestone: February 25, 2011 Assignment Due: March 4, 2011, 10pm 1 Introduction In this assignment you will be constructing a Virtual IP Network

More information

Chapter 3. Unit Testing with JUnit and Debugging. Testing with JUnit getting started. Note

Chapter 3. Unit Testing with JUnit and Debugging. Testing with JUnit getting started. Note Chapter 3. Unit Testing with JUnit and Debugging By now, you are past the basics and should be familiar with developing Java applications using the Eclipse IDE. Although you must be feeling very confident

More information

CSSE 220 Day 3. Check out UnitTesting and WordGames from SVN

CSSE 220 Day 3. Check out UnitTesting and WordGames from SVN CSSE 220 Day 3 Unit Tests and Object References Implementing Classes in Java, using Documented Stubs, Test-First Programming Check out UnitTesting and WordGames from SVN What Questions Do You Have? Syllabus

More information

Final Exam. Kenneth J. Goldman December 18, Name: Student ID Number: Signature:

Final Exam. Kenneth J. Goldman December 18, Name: Student ID Number: Signature: Washington University CSE131. Computer Science I Final Exam Kenneth J. Goldman December 18, 2007 Name: Student ID Number: Signature: Directions: This exam is closed book and closed notes. No electronic

More information

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm)

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm) CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, 2019 11:30pm) This assignment focuses on recursive backtracking. Turn in the following files using the link on the

More information

Array Based Lists. Collections

Array Based Lists. Collections Array Based Lists Reading: RS Chapter 15 1 Collections Data structures stores elements in a manner that makes it easy for a client to work with the elements Specific collections are specialized for particular

More information

DAT159 Refactoring (Introduction)

DAT159 Refactoring (Introduction) DAT159 Refactoring (Introduction) Volker Stolz 1, with contributions by: Larissa Braz 2, Anna M. Eilertsen 3, Fernando Macías 1, Rohit Gheyi 2 Western Norway University of Applied Sciences, Universidade

More information

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1 ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1 Due to CMS by Tuesday, February 14. Social networking has caused a return of the dot-com madness. You want in on the easy money, so you have decided to make

More information

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections Thread Safety Today o Confinement o Threadsafe datatypes Required reading Concurrency Wrapper Collections Optional reading The material in this lecture and the next lecture is inspired by an excellent

More information

Testing and Debugging

Testing and Debugging Testing and Debugging Comp-303 : Programming Techniques Lecture 14 Alexandre Denault Computer Science McGill University Winter 2004 March 1, 2004 Lecture 14 Comp 303 : Testing and Debugging Page 1 Announcements...

More information

CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

More information