4

I'm looking for a unit testing framework for WSH scripts (vbs/wsf, not VB6, VBA).

I can't find anything except this project (looks good, but last activity was recorder around 2 years ago, haven't tested it yet):

http://code.google.com/p/vbslib/

Thanks!

AmonPL
  • 43
  • 3

2 Answers2

3

There also is ScriptUnit and if you just google for "vbscript unittest" you find an ancient posting of mine (not very successful). I'm still interested in the topic and would like to cooperate in a way suitable for you.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • Actually I did find that post, but missed X1 URL (blindness...). Thanks! – AmonPL Apr 08 '11 at 13:16
  • Few questions: 1. How did you manage to execute asserts? I have WSH version 5.8 and I'm getting "Class not registerd" error. 2. How did you include vbs files being tested into test files? (ReadAll, Execute?) – AmonPL Apr 08 '11 at 14:22
  • Sorry, I'm not sure what you are refering to. My unit test 'system' is a bit like the Perl approach (no classes (necessary)), you just call a compare for suitable values; the module 'system' is implemented by ReadAll and ExecuteGlobal; it needs a preprocessing step to get line numbers and syntactic sugar. – Ekkehard.Horner Apr 08 '11 at 15:04
  • @AmonPL - In your Test .vbs files, you can 'include' functions and subs from another .vbs file, using ExecuteGlobal. – JohnZaj Jul 23 '11 at 18:04
  • In the end I decided to migrate scripts to python (and use Jenkins to test them) but Ekkehard.Horner answer is good, as I'm accepting it. Thank you! – AmonPL Jan 10 '12 at 09:54
2

I just pushed a GitHub repo that includes an ultra-lightweight VBScript-based unit testing framework. Right now it only has AssertEqual and AssertErrorRaised, but it would be super easy to add more, if that's even necessary: https://github.com/koswald/VBScript

Here is a snippet from a spec file

With CreateObject("includer")
    Execute(.read("VBSValidator"))
    Execute(.read("TestingFramework"))
End With

Dim val : Set val = New VBSValidator 'Class Under Test

With New TestingFramework

    .describe "VBSValidator class"

    .it "should return True when IsBoolean is given a True"

        .AssertEqual val.IsBoolean(True), True

End With

And here is a sample test launcher

Main
Sub Main
    With CreateObject("includer")
        ExecuteGlobal(.read("VBSTestRunner"))
    End With
    Dim testRunner : Set testRunner = New VBSTestRunner
    With WScript.Arguments
        If .Count Then

            'if it is desired to run just a single test file, pass it in on the 
            'command line, using a relative path, relative to the spec folder

            testRunner.SetSpecFile .item(0)
        End If
    End With

    'specify the folder containing the tests; path is relative to this script

    testRunner.SetSpecFolder "../spec"

    'run the tests

    testRunner.Run
End Sub
  • 1
    Karl, thx. Could you please cut and paste a useful snippet here so this isn't [Your answer is in another castle: When is an answer not an answer](http://meta.stackexchange.com/questions/225370) – Drew Oct 04 '16 at 00:58
  • Thanks for your comment Drew. I made the changes accordingly, I hope. – Karl Oswald Oct 06 '16 at 21:37
  • Thx for sharing Karl :p – Drew Oct 06 '16 at 21:49