【问题标题】:WSH scripts unit testing framework [closed]WSH 脚本单元测试框架
【发布时间】:2011-04-08 12:32:09
【问题描述】:

我正在寻找用于 WSH 脚本(vbs/wsf,而不是 VB6、VBA)的单元测试框架。

除了这个项目我找不到任何东西(看起来不错,但最后一个活动是大约 2 年前的记录器,还没有测试过):

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

谢谢!

【问题讨论】:

    标签: unit-testing vbscript wsh


    【解决方案1】:

    还有ScriptUnit,如果你只是用谷歌搜索“vbscript unittest”,你会发现an ancient posting of mine(不是很成功)。我仍然对该主题感兴趣,并希望以适合您的方式进行合作。

    【讨论】:

    • 其实我确实找到了那个帖子,但是错过了 X1 URL(盲...)。谢谢!
    • 几个问题: 1. 你是如何设法执行断言的?我有 WSH 5.8 版,但出现“类未注册”错误。 2. 你是如何将正在测试的 vbs 文件包含到测试文件中的? (阅读全部,执行?)
    • 抱歉,我不确定您指的是什么。我的单元测试“系统”有点像 Perl 方法(没有类(必需)),您只需调用比较合适的值;模块“系统”由 ReadAll 和 ExecuteGlobal 实现;它需要一个预处理步骤来获取行号和语法糖。
    • @AmonPL - 在您的测试 .vbs 文件中,您可以使用 ExecuteGlobal 从另一个 .vbs 文件中“包含”函数和子项。
    • 最后我决定将脚本迁移到 python(并使用 Jenkins 来测试它们),但 Ekkehard.Horner 的回答很好,因为我接受了它。谢谢!
    【解决方案2】:

    我刚刚推送了一个 GitHub 存储库,其中包含一个基于 VBScript 的超轻量级单元测试框架。目前它只有 AssertEqual 和 AssertErrorRaised,但如果有必要添加更多内容会非常容易:https://github.com/koswald/VBScript

    这是来自spec file的sn-p

    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
    

    这是一个示例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
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-10
    • 2023-04-10
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    相关资源
    最近更新 更多