Self Testing
CSE1110 Software Testing & Quality Engineering Arie van Deursen June 7, 2019
1
Self Testing CSE1110 Software Testing & Quality Engineering - - PowerPoint PPT Presentation
Self Testing CSE1110 Software Testing & Quality Engineering Arie van Deursen June 7, 2019 1 Self Testing exercise System Test Suite observe Self-checks observe exercise Daily Use Operations 2 The Java (C, C++, Python, )
1
exercise
exercise
2
“assert” boolean-expression [“:” string ]
3
public class MyStack() { public Element pop() { assert count() > 0; .... // real method body here .... assert count() == oldCount – 1; } }
4
5
http://wiki.c2.com/?WhatAreAssertions
6
{ preconds } Method { postconds }
Tony Hoare 7
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { favorites.addAll(books); pushNotifications.booksAdded(books); } }
8
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { assert books != null; favorites.addAll(books); pushNotifications.booksAdded(books); } }
9
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { assert books != null; assert !books.isEmpty(); favorites.addAll(books); pushNotifications.booksAdded(books); } }
10
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { assert books != null; assert !books.isEmpty(); assert favorites != null; favorites.addAll(books); pushNotifications.booksAdded(books); } }
11
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { assert books != null; assert !books.isEmpty(); assert favorites != null; assert !favorites.containsAll(books); ... favorites.addAll(books); pushNotifications.booksAdded(books); } }
12
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { assert books != null; assert favorites != null; assert !favorites.containsAll(books); ... if (!books.isEmpty()) { favorites.addAll(books); pushNotifications.booksAdded(books); }}}
13
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { assert books != null; assert favorites != null; // logic to find new books only List<Book> newBooks = ... (books); if (!newBooks.isEmpty()) { favorites.addAll(newBooks); pushNotifications.booksAdded(...); }}}
14
15
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { // assert four preconditions ... // the method body ... // the postcondition. ...?? }}
16
public class FavoriteBooks() { List<Book> favorites; ... public void merge(List<Book> books) { // assert four preconditions ... // the method body ... // the postcondition. assert favorites.containsAll(books); }}
17
18
if (A) { ... if (B) { ... assert PC1 return ...; } else { ... assert PC2 return ...; } } ... assert PC3 return ...;
19
20
21
https://blog.regehr.org/archives/1091
22
23
24
public class FavoriteBooks() { List<Book> favorites; List<Listeners> pushNotifications; protected boolean invariant() { return favorites != null && pushNotifications != null } ... }
25
public class FavoriteBooks() { ... protected boolean invariant() { ... } public FavoriteBooks(...) { favorites = ... pushNotifications = ... ... assert invariant(); } ... }
26
public class FavoriteBooks() { ... protected boolean invariant() { ... } public merge(List<Book> books) { assert invariant(); // assert remaining pre-conditions ... // assert remaining post-conditions assert invariant(); } }
27
public class Node() { Node left; Node right; Node parent; ... protected boolean invariant() { return parentsOK() && orderingOK(); } private boolean parentsOK() { return (left == null || left.parent == this) && (right == null || right.parent == this) } }
28
29
30
public class FavoriteBooks() { @NotNull List<Book> favorites = ... ... public void merge(@NotNull List<Book> books) { assert !books.isEmpty(); assert !favorites.containsAll(books); ... favorites.addAll(books); pushNotifications.booksAdded(books); } }
31
32
Bertrand Meyer Design by Contract
33
34
35
36
37
38
Invariant: I { P } M { Q } class T Invariant: I’ { P’ } M { Q’ } class S
39
Map HashTable HashMap AbstractMap 40
Map
containsKey()
HashMap Hashtable Weak HashMap ...
41
Map
containsKey()
HashMap Hashtable Weak HashMap ... HashMap Test Hashtable Test Weak HashMap Test ... Test
42
Map
containsKey()
HashMap Hashtable Weak HashMap ... MapTest
43
Map
containsKey()
HashMap HashTable Weak HashMap ... HashMap Test Hashtable Test Weak HashMap Test MapTest ... Test
John McGregor: A Parallel Architecture for Class Testing (PACT)
44
Map
containsKey()
HashMap HashTable Weak HashMap ... HashMap Test createMap HashTable Test createMap WeakHash MapTest createMap MapTest createMap ... Test
returns Map returns HashTable
45
Robert Binder (2000): “Polymorphic Server Test”
46
47
48
49
50
51
52
Property: length of concatenated strings equals sum of length of individual strings Quickcheck generates 100 random strings to check this property.
53
54
55
56
57
58
59
60
Poor Precision Poor Recall
61
62
https://courses.cs.washington.edu/courses/cse341/13wi/unit6notes.pdf
63
64
77