150 likes | 312 Views
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 2010. They may not show up well on other PowerPoint versions . You can download PowerPoint 2010 viewer from here .
E N D
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 2010. They may not show up well on other PowerPoint versions. You can download PowerPoint 2010 viewer from here. • These slides contain a lot of animations. For optimal results, watch in slideshow mode.
While you wait for the lecture to start, design test cases for these two methods. • /* Returns true if the name is non-empty and • not null and not longer than 40 chars. */ • publicbooleanisValidName(String name) { • // ... • } • /* Throws StorageException if name is not valid • or if name already exists in the database. */ • publicvoidsaveScore(String name, int score) • throwsStorageException { • if (!isValidName(name)) { • thrownewStorageException("invalid name"); • } • if (Storage.isFound(name)) { • thrownewStorageException("already exists"); • } • Storage.save(name, score); • } When designing test cases, use heuristics covered in Lecture 9.
/* Returns true if the name is non-empty and • not null and not longer than 40 chars. */ • publicbooleanisValidName(String name) { • // ... • } • /* Throws StorageException if name is not valid • or if name already exists in the database. */ • publicvoidsaveScore(String name, int score) • throwsStorageException { • if (!isValidName(name)) { • thrownewStorageException("invalid name"); • } • if (Storage.isFound(name)) { • thrownewStorageException("already exists"); • } • Storage.save(name, score); • }
/* Returns true if the name is non-empty and not null and not longer than 40 chars. */ publicbooleanisValidName(String name) { // ... } Equivalence partitions Values null null empty “ “ , 50 Too long length = 41 Right size 40, 10
/* Throws StorageException if name is not valid • or if name already exists in the database. */ • publicvoidsaveScore(String name, int score) • throwsStorageException { • if (!isValidName(name)) { • thrownewStorageException("invalid name"); • } • if (Storage.isFound(name)) { • thrownewStorageException("already exists"); • } • Storage.save(name, score); • } Equivalence partitions Values null null empty “ “ , 50 Too long length = 41 Right size 40, 10
/* Throws StorageException if name is not valid • or if name already exists in the database. */ • publicvoidsaveScore(String name, int score) • throwsStorageException { • if (!isValidName(name)) { • thrownewStorageException("invalid name"); • } • if (Storage.isFound(name)) { • thrownewStorageException("already exists"); • } • Storage.save(name, score); • } Eq. partitions Values invalid Any invalid e.g. null exists Any existing name e.g. “existing guy” name new Any valid new name e.g. “new guy” score any any
/* Throws StorageException if name is not valid • or if name already exists in the database. */ • publicvoidsaveScore(String name, int score) • throwsStorageException { • if (!isValidName(name)) { • thrownewStorageException("invalid name"); • } • if (Storage.isFound(name)) { • thrownewStorageException("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.
/* Throws StorageException if name is not valid • or if name already exists in the database. */ • publicvoidsaveScore(String name, int score) • throwsStorageException { • if (!isValidName(name)) { • thrownewStorageException("invalid name"); • } • if (Storage.isFound(name)) { • thrownewStorageException("already exists"); • } • storage.save(name, score); • } Do we really need these tests? Short and simple methods
/* Throws StorageException if name is not valid • or if name already exists in the database. */ • publicvoidsaveScore(String name, int score) • throwsStorageException { • if (!isValidName(name)) { • thrownewStorageException("invalid name"); • } • if (Storage.isFound(name)) { • thrownewStorageException("already exists"); • } • Storage.save(name, score); • } Do we really need these tests?
Where we are… • 1: • desc: send budget • deadline: Thu 22nd September • 2: • desc: review buddy program • deadline: Wed 21st September ..s bud
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
Today’s theme ? Nearing completion. Gearing up for bigger projects.
Estimate the statement coverage of this method for these three test cases. • a) about 50% • b) about 80% • c) 100% 1 2 3 4 5 cover {a|b|c} e.g. cover c 77577 tinyurl.com/questionSMS