[L10 Recap eLearning video] Test inputExpected nullfalse Test inputExpected null,0exception Design test cases for these two methods. /* Returns true.

Slides:



Advertisements
Similar presentations
Lecture 2: testing Book: Chapter 9 What is testing? Testing is not showing that there are no errors in the program. Testing cannot show that the program.
Advertisements

Formal Methods and Testing Goal: software reliability Use software engineering methodologies to develop the code. Use formal methods during code development.
Modern Programming Languages, 2nd ed.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Black box testing  Black box tests focus on the input/output behavior of the component  Black-box tests do not deal with the internal aspects of the.
1 CODE TESTING Principles and Alternatives. 2 Testing - Basics goal - find errors –focus is the source code (executable system) –test team wants to achieve.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
1 Joe Meehean. 2 Testing is the process of executing a program with the intent of finding errors. -Glenford Myers.
CSE 403 Lecture 13 Black/White-Box Testing Reading: Software Testing: Principles and Practices, Ch. 3-4 (Desikan, Ramesh) slides created by Marty Stepp.
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
CS1Q Computer Systems Lecture 8
Recursion A method is recursive if it makes a call to itself. A method is recursive if it makes a call to itself. For example: For example: public void.
Neil Ghani Software testing. 2 Introduction In a perfect world all programs fully verified testing thus redundant Back in the real.
1 Intro to Java Week 12 (Slides courtesy of Charatan & Kans, chapter 8)
Testing Testing Techniques to Design Tests. Testing:Example Problem: Find a mode and its frequency given an ordered list (array) of with one or more integer.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
16 October Reminder Types of Testing: Purpose  Functional testing  Usability testing  Conformance testing  Performance testing  Acceptance.
CS 217 Software Verification and Validation Week 7, Summer 2014 Instructor: Dong Si
CS101 Computer Programming I Chapter 4 Extra Examples.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Today’s Agenda  Reminder: HW #1 Due next class  Quick Review  Input Space Partitioning Software Testing and Maintenance 1.
Chapter 5: Structured Programming
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
0 Odds and Ends in Haskell: Folding, I/O, and Functors Adapted from material by Miran Lipovaca.
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved5-2 The switch Statement The switch statement provides another way.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
Testing Data Structures Tao Xie Visiting Professor, Peking University Associate Professor, North Carolina State University
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
COMP Loop Statements Yi Hong May 21, 2015.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
CISC105 – General Computer Science Class 4 – 06/14/2006.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Multiplying Decimals 12/7/2015. To Multiply: You do not align the decimals. Instead, place the number with more digits on top. Multiply Count the number.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Testing Data Structures
WARNING 20 min These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
WARNING 40 min These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
CS161 Introduction to Computer Science
Input Space Partition Testing CS 4501 / 6501 Software Testing
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Structural testing, Path Testing
White-Box Testing.
CHAPTER 4 Test Design Techniques
Module 4 Loops.
CSE 303 Concepts and Tools for Software Development
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Chapter 7 Software Testing.
Software Testing.
WARNING 20 min These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
Presentation transcript:

[L10 Recap eLearning video]

Test inputExpected nullfalse Test inputExpected null,0exception Design test cases for these two methods. /* Returns true if the name is non-empty and not null and not longer than 40 chars. */ public boolean isValidName(String name) { //... } /* Throws StorageException if name is not valid or if name already exists in the database. */ public void saveScore(String name, int score) throws StorageException { if (!isValidName(name)) { throw new StorageException("invalid name"); } if (Storage.isFound(name)) { throw new StorageException("already exists"); } Storage.save(name, score); } count {answer} e.g. count OR tinyurl.com/answerpost Pause video Pause the video while you answer the question.

Test inputExpected nullfalse Test inputExpected null,0exception Design test cases for these two methods using heuristics covered in Lecture 9. /* Returns true if the name is non-empty and not null and not longer than 40 chars. */ public boolean isValidName(String name) { //... } /* Throws StorageException if name is not valid or if name already exists in the database. */ public void saveScore(String name, int score) throws StorageException { if (!isValidName(name)) { throw new StorageException("invalid name"); } if (Storage.isFound(name)) { throw new StorageException("already exists"); } Storage.save(name, score); }

Test inputExpected nullfalse Test inputExpected null,0exception /* Returns true if the name is non-empty and not null and not longer than 40 chars. */ public boolean isValidName(String name) { //... } /* Throws StorageException if name is not valid or if name already exists in the database. */ public void saveScore(String name, int score) throws StorageException { if (!isValidName(name)) { throw new StorageException("invalid name"); } if (Storage.isFound(name)) { throw new StorageException("already exists"); } Storage.save(name, score); } What kind of testing are we using for each method? The first one is black box testing. The second is glass box testing.

Test inputExpected nullfalse Equivalence partitions null empty too long right size Values null “ ” /* Returns true if the name is non-empty and not null and not longer than 40 chars. */ public boolean isValidName(String name) { //... } Groups of inputs that is possibly treated differently from the rest of the input Let’s start with this method.The first thing is to find equivalence partitions.Here’s a reminder what they are.here are the partitions.Let’s pick values from each partition. This one has only one.For this one, we can pick an empty string.Note that it doesn’t have to be zero length.

Test inputExpected nullfalse Test inputExpected nullFalse “ ”False Length==41False Length==50False Length==40True Length==10True Equivalence partitions null empty too long right size Values null “ ” length = 41 40, 10, 50 /* Returns true if the name is non-empty and not null and not longer than 40 chars. */ public boolean isValidName(String name) { //... } Groups of inputs that is possibly treated differently from the rest of the input Let’s pick the boundary value,and a non-boundary value.We can do the same here.And here are the test cases. The grey ones are the less important ones.

/* Throws StorageException if name is not valid or if name already exists in the database. */ public void saveScore(String name, int score) throws StorageException { if (!isValidName(name)) { throw new StorageException("invalid name"); } if (Storage.isFound(name)) { throw new StorageException("already exists"); } Storage.save(name, score); } Test inputExpected nullFalse “ ”False Length==41False Length==50False Length==40True Length==10True null empty too long right size null “ ” Equivalence partitions Values length = 41 40, 10, 50 Now let’s take this method. Note how this method is calling the same method we tested earlier. Does this mean we need to test all those cases here again? Let’s see how it goes.

Eq. partitions invalid exists new Values Any invalid e.g. null Any existing name e.g. “existing guy” Any valid new name e.g. “new guy” name scoreany /* Throws StorageException if name is not valid or if name already exists in the database. */ public void saveScore(String name, int score) throws StorageException { if (!isValidName(name)) { throw new StorageException("invalid name"); } if (Storage.isFound(name)) { throw new StorageException("already exists"); } Storage.save(name, score); } Test inputExpected “new guy”, 0success null, -3exception “existing guy”, 5exception When picking equivalence partitions, we consider groups of values THIS method is likely to treat in the same way.For example, this method treats all invalid names the same way, irrespective of why the name is invalid.Here are the other two partitions for the name.The method treats all scores the same way, so there is only one partition for that.And here are the test cases.

/* Throws StorageException if name is not valid or if name already exists in the database. */ public void saveScore(String name, int score) throws StorageException { if (!isValidName(name)) { throw new StorageException("invalid name"); } if (Storage.isFound(name)) { throw new StorageException("already exists"); } Storage.save(name, score); } Integration tests are choreography tests. They do not test components. They test how well the assembly of components dance together. Test inputExpected nullFalse “ ”False Length==41False Length==50False Length==40True Length==10True Test inputExpected “new guy”, 0success null, -3exception “existing guy”, 5exception If Unit testing, we should use stubs for isValidName etc. We did not re-test all these test cases we used for testing the isValidName method. That is because this is an integration test. This method is integrating three other methods. We assume that those methods have already been tested and are working correctly. Our concern here is to find if they are working together correctly, as required by this method. That is the difference between unit tests and integration tests. Note that if we are unit testing this, we should have used stubs for the three methods, to isolate this method from those three. In cases like this, it is ok to skip unit testing and go straight to integration testing.

Short and simple methods /* Throws StorageException if name is not valid or if name already exists in the database. */ public void saveScore(String name, int score) throws StorageException { if (!isValidName(name)) { throw new StorageException("invalid name"); } if (Storage.isFound(name)) { throw new StorageException("already exists"); } storage.save(name, score); } Test inputExpected “new guy”, 0success null, -3exception “existing guy”, 5exception Do we really need these tests? If you think this method is so simple that it doesn’t even need testing,take it as an inspiration to write short simple methods. It can reduce the risk of bugs greatly.

/* Throws StorageException if name is not valid or if name already exists in the database. */ public void saveScore(String name, int score) throws StorageException { if (!isValidName(name)) { throw new StorageException("invalid name"); } if (Storage.isFound(name)) { throw new StorageException("already exists"); } Storage.save(name, score); } Test inputExpected “new guy”, 0success null, -3exception “existing guy”, 5exception Do we really need these tests? But avoid the temptation to skip testing. Even a broken clock looks as if it’s working twice a day. Just because the code looks right doesn’t mean it is right. Test anyway.

..s bud 1: desc: send budget deadline: Thu 22 nd September 2: desc: review buddy program deadline: Wed 21 st September Where we are… Now you should be close to a product that is at least usable to yourself. The next step is to polish it until it becomes a gem of a product. While we are on the subject of polishing gems, let’s see this video of a traditional gem polishing technique.

1. Aim to create a gem you will be proud to wear 2. Polish, check, polish, check, polish, check,… 3. Sharpen your tools once in a while Three things to remember. One: Aim for a gem, not a brick. Two: Tweak the product a little and try it out yourself. Rinse and repeat. Three: Notice how the gem polisher sometimes sharpen his tool instead of polishing gems. Likewise, spend some time improving the way you do things and the tools you use. That can pay dividends in the long run. Remember, the product is not the main thing. What you become is more important.

Today’s theme Nearing completion. Gearing up for bigger projects. ? Today, we are going to learn a few things that will prepare you for bigger projects.

Estimate the total statement coverage of this method for these three test cases. a) about 50% b) about 80% c) 100% cover {a|b|c} e.g. cover c Test inputExpected “new guy”, 0success null, -3exception “”, 5exception OR tinyurl.com/answerpost Pause video Before that, you can try this question.Pause the video while you think of the answer.The first test case executes these lines. The second test case executes line 2 in addition to the ones executed previously. The third test case does not execute any more new lines. Therefore, the total coverage is about 80%.