testing fun

domm on 2008-07-03T16:03:41

So, I'm currently developing a single-sign-on system for $work. Because I'm a well-behaved coder, I write tests. Which was fun today. In order to test the communication of the SSO-"Client" (i.e. the website the user actually wants to log on to) with the SSO-"Server" (the one SSO system), I had to:

  1. Generate a very small Catalyst TestApp (the "client")
  2. run the TestApp in a test (easy thanks to Catalyst::Test)
  3. write some fixures (connect to DB, generate a user to play around with, generate a login token directly in the DB)
  4. start the "server" by forking off another process and start another Catalyst app in the child
  5. Call the action in the "client" that's triggered after the user actually logged in on the SSO server.
  6. In this action, send an XMLRPC (ok, JSONRPC) request to the server running in the forked process.
  7. Take the result of the JSONRPC, store the values in the session & mark the user as authenticated
  8. Redirect to some page in the TestApp that is rigged to only display the username
  9. Check if the username matches the one generated for the testuser (see 3.)
  10. Kill the forked process
  11. Remove the fixtures

And it usernames matched! Even after setting the username to 'Rüştü Reçber' (yes, we're using the names of soccer players (especially ones with lots of non-latin1 characters) for test values - call it collateral damage of the EM...) (to bad that use.perl doesn't like utf8 chars in links, which means that the wikipedia link to poor old Rüştü is broken..)

/me likes testing


Better Link

Ovid on 2008-07-03T16:14:21

Try this link for him

Tests are great

ajt on 2008-07-03T19:12:32

At work I mostly work with SAP which requires user testing which is hard to sensibly automate (given the small size of our system). Our test coverage is terrible and we often get problems appearing days, weeks or months after code is moved in to live that should have been picked up in testing.

At home where I mostly code in Perl and work when I can code in Perl I like the tests, it really helps improve your code and testing is a benefit not a chore in my opinion.

All I have to figure out now is why my module fails it tests for one user and not anyone else. CPAN Testers is great, but when you can't replicate the problem yourself you do feel a little stumped..!