[Q] TDD example for client/server development?

Diego Fernandez diegof79 at gmail.com
Sun Dec 3 00:28:43 UTC 2006


I have done a lot of TDD for client/server (web services, http,
GemStone, LDAP) and my experience is this:

- First of all focus in what behavior you are testing: are you testing
all the communication framework or are you testing the client (or
server) behavior? This is important because in most cases the
communication framework is already done, so you don't need to test it
again, ie testing (directly or indirectly) that the Socket object
works is non sense, unless you are writing the behavior for the Socket
object.

- Create a unit test for the client side, "mocking" the server side.
Maybe you may need to re-think your design to be more decoupled from
transport mechanism or specific communication frameworks, but I think
that is a good side effect of TDD :)
- Do the same for the server.

So now, you  have "simple" tests for the client and the server :)

Then you can make a more complex test that initializes the server on
#setUp, and them does a shutdown in #tearDown.
Another option is to start up the server in the #setUp of a
TestResource, so the server could remain running during the execution
of all the tests.

Note that kind of tests is not in the "spirit" of unit tests, because
they test a lot more (you are testing the client, the server, the
communication protocol and the communication transport in one test),
an usually requires external resources to run...
But they are very useful too! So you can do them using the SUnit
framework, but running them apart from the rest of the unit tests.
(this is just a development practice... I usually have a TestSuite of
"Unit Tests" and a TestSuite of "Integration Tests" or "User Story
Tests")

For your question about the "echo" server test, you could do something
like this (this is a really silly example...):

EchoServerIntegrationTest>>#setUp
          server := EchoServer configuredBy: self serverConfiguration.
          server startUp.

EchoServerIntegrationTest>>#testCommunicationResponse
          | client |
          "Note that EchoClient it's a proxy of EchoServer, so maybe both have
          protocol, like #echo:... maybe you can call them Parrot and
ParrotProxy :P"

          client := EchoClient connectedTo: self serverLocation.
          self assert: (client echo: 'hello') = 'hello'.

          "There is a lot of details that you need to think in a more
complex client/sever
          app, for example maybe you have to reify the concept of 'session' "

EchoServerIntegrationTest>>#tearDown
         (server isNil or: [server notStarted ]) ifTrue: [^self ].
         server shutDown

I hope it helps,
Diego,-

On 12/1/06, Sungjin Chun <chunsj at embian.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> I'm finding example code/doc for simple echo server/client development
> using TDD. I've found many examples for TDD, however, they are mostly
> for simple single application only.
>
> Can anyone help me?
>
> Thank you in advance.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.2 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFFcORKQqspS1+XJHgRAsX+AJ47lv+WU/WogDjLRiRERR9zKP0aYgCeIrfY
> ZhZl7bSGRlD14+N+xuoO+tA=
> =Tt1X
> -----END PGP SIGNATURE-----
>
>



More information about the Squeak-dev mailing list