Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Ma Armored Code
Last updated at 10:05 pm UTC on 5 December 2006
MaArmoredCode is an extension to the SUnit testing that assists with automating the testing of network programs by conducting the test through remote-perform calls to other Squeak images.

The test is executed "one-click". It doesn't work with the SUnit test browser, instead you do in a workspace:
	MyNetworkProgramTestCase kickoff

At this point, the equivalent of World Menu | save as... is run, for the conductor image and each player image (and its changes file). They are exact copies of this image, so they all have the same test-case code. However, each is running its own server that is listening for requests from the conductor image.

The conductor image waits for them to start, then runs #setUpSuite.
setUpSuite
	super setUpSuite.
	self
		addPlayerNamed: 'client1';
		addPlayerNamed: 'client2';
		addPlayerNamed: 'server'

(Note, there is more subclassResponsibility; it hard-codes the image filenames, this could and should be reified).

Since these are network programs, you may want do additional initialization at this point (rather than after each and every #test method). At this point, you can #remotePerform any initialization necessary to the other players.

An instance of the MyNetworkProgramTestCase is then finally created and run in the conductor image. The standard #setUp and #tearDown are called for each test, and of course still having remote-perform access to all of the network players via #remotePerform:[withArguments:, etc.].

There are only 10 instance methods on MaNetworkTestCase which are self-explanatory.

The #test methods of your MyNetworkProgramTestCase are run in the conductor image, but the methods they remote perform are also implemented on MyNetworkProgramTestCase, so methods can proliferate, but categories help keep things straight and it's real easy. State may also be passed via argument (any object can be used, but add to the #playerProtocol if necessary).

  self
    remotePerform: #commitPersonSample:
    withArguments: Person new  "be sure to include Person in your #playerProtocol"
    in: 'client1'.
  self
    remotePerform: #verifyPersonSample
    in: 'client2'.

Use #tearDownSuite to handle remote telling players to close down.

An example is included with the test cases for Ma client server. For another example, see About the MagmaTester.