WSH scripts unit testing framework [closed]

こ雲淡風輕ζ 提交于 2019-12-07 06:59:02

问题


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!


回答1:


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.




回答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


来源:https://stackoverflow.com/questions/5595067/wsh-scripts-unit-testing-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!