2011-04-08 45 views

回答

3

还有ScriptUnit,如果你只是谷歌的“VBScript单元测试”,你会发现an ancient posting of mine(不是很成功)。我仍然对这个话题感兴趣,并希望以适合您的方式进行合作。

+0

其实我找到了这个帖子,但是错过了X1的URL(失明......)。谢谢! – AmonPL 2011-04-08 13:16:02

+0

几个问题: 1.您是如何设法执行断言的?我有WSH版本5.8,我得到“类未注册”的错误。 2.您是如何将正在测试的vbs文件包含到测试文件中的? (ReadAll,Execute?) – AmonPL 2011-04-08 14:22:52

+0

对不起,我不确定你在说什么。我的单元测试“系统”有点像Perl方法(没有类(必要)),你只需要调用一个比较来得到合适的值。模块“系统”由ReadAll和ExecuteGlobal实现;它需要一个预处理步骤来获得行号和语法糖。 – 2011-04-08 15:04:07

2

我刚推了一个GitHub仓库,其中包含一个基于VBScript的超单元测试框架。现在它只有assertEqual便和AssertErrorRaised,但它是超级容易添加更多,如果这甚至是必要的:https://github.com/koswald/VBScript

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

一个片段,并在这里是一个样本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。你能否在这里剪切和粘贴一个有用的片段,所以这不是[你的回答是在另一个城堡:何时是一个答案不是答案](http://meta.stackexchange.com/questions/225370) – Drew 2016-10-04 00:58:25

+0

谢谢你的评论德鲁。我希望,我做了相应的改变。 – 2016-10-06 21:37:24

+0

Thx分享Karl:p – Drew 2016-10-06 21:49:47