Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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:

1 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 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.

2 77577 OR tinyurl.com/answerpost
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. */ 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 input Expected null false Test input Expected null,0 exception How many test cases do you have for the saveScore method? count {answer} e.g. count 9 OR tinyurl.com/answerpost

3 Test input Expected null false Test input Expected null,0 exception
/* 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 input Expected null false Test input Expected null,0 exception

4 Equivalence partitions
/* Returns true if the name is non-empty and not null and not longer than 40 chars. */ public boolean isValidName(String name) { // ... } Test input Expected null false Test input Expected null False “ ” Length==41 Length==50 Length==40 True Length==10 Equivalence partition = A group of inputs that are likely to be treated similarly by the SUT. Equivalence partitions Values null null empty “ ” too long length = 41 , 50 right size length = 40, 10

5 Equivalence partitions
/* 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 input Expected null False “ ” Length==41 Length==50 Length==40 True Length==10 Equivalence partitions Values null null empty “ ” too long length = 41 , 50 right size length = 40, 10

6 Any existing name e.g. “existing guy”
/* 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 input Expected “new guy”, 0 success null , -3 exception “existing guy”, 5 Eq. partitions Values invalid Any invalid e.g. null name exists Any existing name e.g. “existing guy” new Any valid new name e.g. “new guy” score any any

7 Is this a unit test or an integration test?
/* 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 input Expected “new guy”, 0 success null , -3 exception “existing guy”, 5 Is this a unit test or an integration test? Integration tests are choreography tests. They do not test components. They test how well the assembly of components dance together. If Unit testing , we should use stubs for dependencies isValidName etc.

8 Do we really need to test this method?
/* 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 input Expected “new guy”, 0 success null , -3 exception “existing guy”, 5 Do we really need to test this method? Short and simple methods

9 Nearing completion. Gearing up for bigger projects.
Today’s theme ? Nearing completion. Gearing up for bigger projects.


Download ppt "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."

Similar presentations


Ads by Google