News Story



Published at 4:20pm on 20 Apr 2008

We've added REALunit, a new open source unit testing framework for REALbasic to our open source software page.

The REALunit library gives you all the tools you need to set up unit testing suites for your REALbasic applications.

In any reasonable-sized project there will be complex interaction between classes, and when something goes wrong it can be difficult to isolate exactly which component is at fault. Also, for a program with a complex scope, it can often be difficult and tedious to test all possible inputs to make sure that they all work correctly.

The basic concept of unit testing is that you create test methods whose sole function is to test that the other methods and classes in your project are behaving the way you expect. This can involve some extra work initially, but it means that you can the test for all possible inputs automatically every time the program runs. It avoids the "this bit of code is complicated, I better not touch it in case I break something" mentality - if you do break something, the unt test will tell you exactly what and where.

REALunit is designed to make unit testing as simple and intuitive as possible. In a traditional Java program one would write a unit test class to mirror every class in the program, and within that test class would be a test method to mirror each method of the class being tested. This approach is very thorough, but literally means writing everything twice.

REALunit will allow you to work this way, but because it uses interfaces (or introspection, if you have RB2008 or later), there is no need to create separate test classes in most cases - you can simply add test methods directly to your existing classes.

Finally, if you're not keen on the whole unit testing concept, REALunit provides a set of Assertion methods, which are an intuitive way to check that your assumptions are true without actually writing a test suite. As you are writing your program, whenever you find yourself thinking "This variable will always be true", or "This object should never be nil", you can put in an assertion stating that assumption explicitly in code. If your assumption is correct, everything will work as you expect. If it's wrong then the program will throw an exception immediately, instead of carrying on indefinitely until your mistake causes something to blow up further down the line, where it might be harder to diagnose.

Like all our open source offerings to date, the REALunit library is protected by the PKWARE zlib/pnglib licence. Similar to the BSD or MIT licence, this places very few restrictions on how the software is used, and does not require that any derived works must themselves be open source or non-commercial.