. .


ST 4U 90: Test Driven Development in VA Smalltalk

June 3, 2011 13:03:04.116

Today's Smalltalk 4 You looks at loading and using SUnit in VA Smalltalk. SUnit is the standard way of supporting TDD in all Smalltalk dialects - and it's easy to use in VA. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:


If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll look at using SUnit (for unit testing) in VA Smalltalk. The first step is to use the Load/Unload Features menu pick to bring in SUnit support (along with all of the associated tools built into VA for it):

Load SUnit

In the feature list UI, scroll down to SUnit, select it, and hit the >> button to move it to the right. Then click the Ok button to load the code:

Load SUnit

Now that SUnit support is loaded, we need to create a new application that will contain our test class. We'll be building a simple test case for the previously created CounterApp - which means that our new application will need some pre-requisites to make the appropriate classes visible. First, create the application, and add the pre-reqs using the picker:

Create the Application

Create the Application

Add pre-reqs

Now we can define the new test case class. This is no different from creating any other class, but if you didn't add SUnit as a pre-req, the TestCase class won't be visible to your new application. The next few images walk through creating the class:

Create the Class

Create the Class

Now, we can write a standard SUnit testcase. Create a method that begins with the word test - that's how SUnit finds the tests in your subclass of TestCase. The last part of the method should send the #assert: message, with the argument being an expression that answers a boolean. Below is the simple example that tests the #addOne method in Counter:


Now, go back to the tools menu, and pulling the SUnit option right, select the SUnit Browser:

SUnit Browser

That opens a tool showing all of the tests present in your VA image. There are ways to be more specific about what you see in this tool; we'll cover that in another tutorial. For now, simply scroll down to the test you created and select it

SUnit Browser

Finally, press the Run button, and you should see two green bars and some information. If you see red, either the CounterApp has a bug, or your test is wrong.

SUnit Browser

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , , ,

[st4u90-iPhone.m4v ( Size: 8945432 )]

posted by James Robertson

 Share Tweet This