An Io testing framework

I couldn’t go on for much longer in Io without somehow testing my code. I’m okay with printing out results for a little while, but as soon as i come to refactoring my code i feel the need to assert somehow the results i’m expecting.

I had a nice chat with Matt Pep about it and tried a few things before i came to the idea of adding a shouldEqual slot on Object so that anything can assert equality.

Object shouldEqual := method(expected,
  if(self == expected,
    "." print,
    ("Expected " .. self .. " to equal " .. expected) println

This means i can do a few things like this:

myList := List2d clone
myList dim(3, 5)
myList items size shouldEqual(5)

And things like this:

myList set(2, 3, "Middle")
myList get(2, 3) shouldEqual("Middle")

The only question i have now is: how do i take that assertEqual slot definition out of this file and into a file of its own that i can include everywhere from now on?

I’d like to do something like:


How would you do such a thing in Io?

I’m afraid i still haven’t finished Day 2’s exercises yet! I must move on to Day 3 tomorrow …! :)


Susan Potter has found the answer! I will try this later: Io’s “require”


5 comments on “An Io testing framework

  1. It seems you can do “doFile(‘’)”. It’s executed inside the Lobby if you do it like that, but you can call it from other objects.

    More info in the Guide:

    (Sorry, no direct link, scroll down or CTRL-F doFile)

    I would also point out that there’s built-in UnitTest object.

    Io comes with an “auto test battery” that uses that lib. Here’re the tests of Date, for example:

    Curiously, the tests for the UnitTesting lib are missing … Enrique Comba would not approve that.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s