Professional Documents
Culture Documents
courses.cs.washington.edu/courses/cse403/16au/
System Testing
Emina Torlak
emina@cs.washington.edu
Outline
2
recap
system testing
System testing
4
System testing
4
test
integration testing
Integration testing
6
Stubs: a way to test a partial system
7
Testing with stubs (1/3)
8
Testing with stubs (2/3)
9
Testing with stubs (3/3)
10
Where to inject stubs?
• You should not have to change A's code everywhere (beyond using
your interface) in order to use your Stub B. (a "testable design")
11
Mock objects: a way to test interactions
12
Stubs vs mocks
communicate
class under
stub (B)
test (A)
assert
test
13
Stubs vs mocks
• A stub (B) gives out data that goes • A mock (B) waits to be called by
to the object/class under test (A). the class under test (A).
• The unit test directly asserts • It may have several methods it
against A, to make sure it gives the expects that A should call.
right result when fed B’s data. • It makes sure that it was called in
exactly the right way.
• If A interacts with B the way it
should, the test passes.
communicate communicate
class under class under
stub (B) mock (B)
test (A) test (A)
assert assert
test test
13
Mock object frameworks
14
A jMock example
@RunWith(JMock.class)
public class ClassATest {
private Mockery mockery = new JUnit4Mockery(); // initialize jMock
@Test public void testACallsBProperly1() {
// create mock object to mock InterfaceB
final InterfaceB mockB = mockery.mock(InterfaceB.class);
15
Using stubs and mocks together
16
Using stubs and mocks together
16
Using stubs and mocks together
logError(String)
LogAnalyzer StubWebService
sendEmail()
assert
test MockEmailSender
16
test
performance testing
Acceptance, performance
• Performance is important.
• Performance is a major aspect of program acceptance by users.
• Your intuition about what's slow is often wrong.
Donald Knuth
18
Thinking about performance
19
Thinking about performance
19
Thinking about performance
19
Thinking about performance
19
Profile and measure before optimizing
• Memory usage
• what kinds of objects are on the heap
• where were they allocated
• who is pointing to them now
• "memory leaks" (does Java have these?)
20
Profile and measure before optimizing
• Memory usage
• what kinds of objects are on the heap
• where were they allocated
• who is pointing to them now
• "memory leaks" (does Java have these?)
20
Optimization hints: think high-level
21
Optimization hints: think high-level
21
Optimization hints: think high-level
21
Summary
22