Accept(); // Accept after Connect does not block
client.Send(command);
received = server.Receive();
server.Send(temperature);
response = client.Receive();
Assert.AreEqual(command, received);
Console.WriteLine("Server sent {0,5:F1}, client received {0,5:F1}",
temperature, response);
Assert.AreEqual(temperature, response);
client.Close();
server.CloseConnection();
server.Close();
} // LogOneSample
Figure 2.10. Test method for client/server scenario.
method??™s behavior. But many methods are not state-independent. This introduces
complications, as we shall now see.
2.8 A more complex scenario
We would like to write tests that exercise more of the behavior exhibited by the
applications. Our test method LogOneSample tests the smallest realistic run: the
client requests one temperature sample and the server responds (Figure 2.10).
28 Why We Need Model-Based Testing
A realistic test of a client/server system tests one end at a time, the client or the
server. From the point of view of each end, the other end is nondeterministic: its
behavior cannot be predicted. This poses practical problems for coding tests. Here
we avoid these problems by creating a sandbox, a testing environment where we
remove the nondeterminism by controlling both client and server. Both can run on
the same computer, and use the localhost IP address. In fact, we can call both client
and server methods from the same test method.
Pages:
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61