27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

18 <strong>Why</strong> <strong>We</strong> <strong>Need</strong> <strong>Model</strong>-<strong>Based</strong> <strong>Testing</strong><br />

}<br />

}<br />

// ... continued<br />

public string Receive()<br />

{<br />

int nbytes = connectionSocket.Receive(receiveBuf);<br />

string command =<br />

System.Text.Encoding.ASCII.GetString(receiveBuf,0,nbytes);<br />

return command; // command.Length = 0 means connection closed<br />

}<br />

public void Send(double datum)<br />

{<br />

string response = String.Format("{0:F1}", datum); //1 decimal digit<br />

byte [] sendBuf = System.Text.Encoding.ASCII.GetBytes(response);<br />

connectionSocket.Send(sendBuf);<br />

}<br />

public void CloseConnection()<br />

{<br />

connectionSocket.Close();<br />

}<br />

public void Close()<br />

{<br />

listenerSocket.Close();<br />

}<br />

Figure 2.4. Remote instrument server class (2).<br />

In the .NET framework, a collection of code that is compiled together (in one csc<br />

command) is called a source program. In this simple example, the source program<br />

is a single class in a single file. Usually, the source program for a library comprises<br />

several classes or other types in several files. Compiling a source program creates<br />

a binary file called an assembly. Assemblies are the software components of the<br />

.NET framework. A library is an assembly intended for use by applications (or<br />

other libraries); it has no main method. A library has the file type dll.<br />

<strong>We</strong> create another library for the server class. <strong>We</strong> create a third library for the<br />

temperature sensor class, Temperature (Figure 2.6). This class provides a Sample<br />

method that acquires one sample from the temperature sensor, and a ConvertToCelsius<br />

method that converts a temperature sample from Fahrenheit to Celsius. This<br />

version of Temperature is a simulator; it provides a stub Sample method that does<br />

not require actual sensor hardware, so you can use it on any computer that provides<br />

the .NET framework.<br />

more free ebooks download links at:<br />

http://www.ebook-x.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!