Unit Testing and Todo Lists in VBA: Announcing Rubberduck Version 1.0

Have you ever wanted to properly unit test your VBA code or simply wished the VBA editor had a Task List window that picked up your Todo comments? The wait is over friends. It’s here.

For the last month Mathieu Guindon and I have been working pretty tirelessly on an open source COM Add-in for the VBA Editor written in C#. Both of us spend a lot of time programming for Office and just got tired of the VBE’s (Visual Basic Editor’s) lack of functionality. As much as Microsoft has tried to move people away from VBA, it doesn’t seem that it is going away any time soon. VBA remains a great solution to many of our Office automation tasks, but the VBA IDE itself has not seen any real changes in over a decade. Even the most popular add-ins haven’t seen an update in a very long time. We all deserve a modernized editor and it’s our goal to bring the VBA IDE into the 21st century.

Today I couldn’t be more excited to tell you that we’ve just released version 1.0 of the software. It’s been a lot of work to get here and we’re just getting started. Without any further ado, it is my honor to present to you…

Rubberduck VBE Add-In

Every Programmer Needs a Rubberduck

What’s in Version 1.0?

Boiler-Plate Free Unit Testing

There are a few Unit Testing frameworks out there for VBA. Most of them written in native VBA code and, as a result, they require a lot of boiler plate to function. Tests should be easy to write and run. If they’re not, programmers simply won’t use them. RubberDuck eliminates nearly all of the boilerplate and provides a Test Explorer that lets you decide which tests to run at the click of a button. Mat has truly outdone himself here.

Just add a @TestModule attribute and one line of code. That’s all you need to be ready to start writing your tests.

    '@TestModule
    Private Assert As New Rubberduck.AssertClass

Or alternatively, use the Test Explorer to add a new test module for you.

AddTestModule

To write a test, just add the @TestMethod attribute to any public sub in the test module.

    '@TestMethod
    Public Sub OnePlusOneEqualsTwo
        Assert.AreEqual 2, Add(1,1)
    End Sub

Refresh the Test Explorer and it will automatically add your new test to the list.

TestExplorer

“Todo:” Comments and Task List

Most modern IDEs have some sort of task list that looks at the comments in your projects and adds items with special comments automatically to the list. The VBE is notably lacking this functionality. Rubberduck fills this gap.

Out of the box Rubberduck will pick up comments with the following markers, but it can be configured to pick up any number of custom markers.

    'Todo:
    'Note:
    'Bug:

TodoExplorer

Double-clicking on any found todo item will jump you to that line of code.

Code Explorer

Ever wish you could drill down beyond the module level in the Project Explorer? Now you can with our Code Explorer.

CodeExplorer

Again, a double-click will jump you to that location in the code.

How can I get Rubberduck?

Unlike a lot of open source projects out there, we’ve created an installer. You can head on over to our releases page and download it. Setup is a breeze. Just a few clicks in the wizard and you’re ready to go.

Alternatively, you can clone the repository and compile the project yourself to get the latest copy. We keep the master branch in a working and buildable state, but there may be incomplete features and possibly a few more bugs than the release version.

How can I contribute?

Anyway you’d like really. Check out the issues page to see if there’s a feature you’re interested in implementing or a bug you’d like to fix. What we really need most right now is people using the add-in to find and submit bugs. I’ve been using Rubberduck for a few weeks now, but the more eyes on, the better. Our wiki and test coverage could use some love too though.

What’s coming in future releases?

Well, we have a lot of things planned, so I’m going to cop out and refer you to the Milestones page. I’m currently working on making Rubberduck easier to customize and configure, but Mat keeps babbling about being ReSharper™ for VBA. There are some very cool things in store and, like I said, we’re just getting started. If you think of a feature you’d like to see added, create a fork and implement it, or submit your request as an issue.

Remember friends, Every Programmer Needs a Rubberduck.

, , , , , , , ,

  1. #1 by retailcoder on November 30, 2014 - 10:21 pm

    Reblogged this on retailcoder.

    Like

  2. #2 by Dick Kusleika on December 29, 2014 - 11:26 pm

    Is @TestMethod just a comment above the sub? Does is have to be a class module? I tried to replicate what you have above, but I can’t get it to work. The TestExplorer menu item doesn’t seem to do anything, nor does Run All Test.

    Like

    • #3 by Christopher J. McClellan on December 30, 2014 - 12:21 am

      It is just a comment and it actually needs to be a standard module (*.bas). The easiest thing to do is to use the TestExplorer to add new test modules and methods, but it appears thats not working for you. Which version did you install and what Office App are you working with? We realized late that it was only working with Excel and have since added support for Word and Access.

      Like

      • #4 by Dick on December 30, 2014 - 12:45 am

        Excel 2010 32-bit (14.0.7140.5002) and Rubberduck.v1.01-alpha2.Setup

        My module looks like this
        Option Explicit

        '@TestModule
        Private Assert As New Rubberduck.AssertClass

        '@TestMethod
        Public Sub OnPlusOneEqualsTwo()
        Assert.AreEqual 2, Add(1, 1)
        End Sub

        Like

      • #5 by Christopher J. McClellan on December 30, 2014 - 12:58 am

        I’m grasping at straws here, but you probably need to allow access to the editor by taking the following steps. Go to File>>Options>>Trust Center>>Trust Center Settings>>Macro Settings and check the “Trust access to the VBA project object model”.

        Like

  3. #6 by retailcoder on December 30, 2014 - 1:48 am

    Rubberduck will only try to discover test methods in standard modules (.bas) that have a @TestModule “attribute” / comment in their declarations section. Test methods must be public, parameterless “Sub” procedures either named “Test*” (i.e. with a name that starts with “Test”) or decorated with a @TestMethod “attribute” / comment, and the AssertClass instance requires a reference to the Rubberduck type library.. but all that is automagic using the test explorer – if the Test Explorer menu doesn’t bring up the test explorer dockable window then something is broken with the installation / registration of the COM components involved… but that would be surprising. If the Test Explorer menu does bring up the dockable window, selecting “New test module” from the “Add” menu would add a new standard module, reference the Rubberduck type library and add the “@TestModule” magic comment and an instance of the AssertClass called “Assert”, ready to be used in test methods.

    Like

  4. #7 by retailcoder on December 30, 2014 - 1:49 am

    Oh and trusted programmatic access to the VBE shouldn’t be necessary.

    Like

  5. #8 by bervukas on May 6, 2016 - 6:11 am

    Hey Chris,

    Just wanted to let you know I’ve written “A Very Simple Excel VBA Unit Testing Tutorial” using Rubberduck: http://www.bernardvukas.com/excel-vba-unit-testing-tutorial/

    Best,
    Bernard

    Liked by 2 people

  6. #9 by Łukasz Solarski on June 17, 2016 - 12:00 pm

    I simply LOVE you:)

    Like

    • #10 by Christopher J. McClellan on June 17, 2016 - 3:18 pm

      Thanks! Be sure to check out the 2.0 beta release! I haven’t been very involved since 1.4, but I hear it’s a vast improvement.

      Like

Leave a comment