亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

VB6-單元測試工具ComUnit

系統 2270 0

在使用過NUnit后,一直想在VB6中使用一下單元測試工具,目前比較流行的是VBUnit和ComUnit,我比較喜歡ComUnit主要是它是開源的,當然用起來比較爽了,可以在 http://comunit.sourceforge.net/ 進行下載。

ComUnit使用比較簡單,注意下邊幾點后就可以使用了。

' ?COMUnit?1.1?-?TestRunner?form

Option ? Explicit

' ?Initialize?the?TestRunner?control
Private ? Sub ?Form_Load()
????
' ?TODO:?add?instances?of?your?TestContainer?classes?to?the?UnitRunner?control
???? ' ?e.g.?UnitRunner1.AddTestContainer?New?TCTestContainer
???? ' ************************************************
???? ' 必須向UnitRunner添加一個控制對象,別的不需要修改
????UnitRunner1.AddTestContainer? New ?TCTestContainer
????
' ************************************************
End?Sub

' ?Run?the?tests?selected?in?the?UnitRunner
Private ? Sub ?btnRun_Click()
????UnitRunner1.Run
End?Sub

' ?Close?the?form
Private ? Sub ?btnClose_Click()
????Unload?Me
End?Sub

' ?Resize?the?UnitRunner?control?and?the?buttons?on?the?form
Private ? Sub ?Form_Resize()
????UnitRunner1.Move?
0 ,? 0 ,?ScaleWidth,?PosInt(ScaleHeight? - ?btnClose.Height? - ? 50 )
????btnClose.Move?PosInt(ScaleWidth?
- ?btnClose.Width),?PosInt(ScaleHeight? - ?btnClose.Height)
????btnRun.Move?PosInt(ScaleWidth?
- ?btnClose.Width? - ?btnRun.Width? - ? 100 ),?PosInt(ScaleHeight? - ?btnRun.Height)
End?Sub

Private ? Function ?PosInt(iValue)? As ? Integer
????PosInt?
= ?IIf(iValue? > ? 0 ,?iValue,? 0 )
End?Function
' ?COMUnit?1.1?-?TestContainer?Class
'
建議類的前綴為TC
Option ? Explicit

' ?Interface?declaration
Implements?ITestContainer

' ?Fixture?Member?Variables
'
?TODO:?specify?your?TestContainer?test?fixture?member?variables?here

' ?Return?the?name?of?the?different?test?case?methods?in?this?test?container
Public ? Property ? Get ?ITestContainer_TestCaseNames()? As ?Variant()
????
' ?TODO:?add?the?names?of?your?test?methods?as?a?parameter?into?the?Array()?function
???? ' 必須將測試方法的名字加到數組中
????ITestContainer_TestCaseNames? = ? Array ( " TestString " ,? " TestLong " )
End?Property

' ?Run?the?specified?test?case?methods?in?this?test?container
Public ? Sub ?ITestContainer_RunTestCase(oTestCase? As ?ITestCase,?oTestResult? As ?TestResult)
????
On ? Error ? GoTo ?ErrorHandler
????InvokeHook?Me,?oTestCase.Name,?INVOKE_FUNC,?oTestResult
????
' ?CallByName?Me,?oTestCase.Name,?VbMethod,?oTestResult
???? Exit ? Sub
ErrorHandler:
????oTestResult.AddError?Err.Number,?Err.Source,?Err.Description
End?Sub

' Initialize?the?test?fixture
Public ? Sub ?ITestContainer_Setup()
????
' ?TODO:?initialize?your?test?fixture?here
End?Sub

' Destroy?the?test?fixture
Public ? Sub ?ITestContainer_TearDown()
????
' ?TODO:?destruct?your?test?fixture?here
End?Sub

' Public?Sub?testSampleMethod(oTestResult?As?TestResult)
???? ' ?TODO:?add?your?test?code?here
'
End?Sub

Public ? Sub ?TestString(oTestResult? As ?TestResult)
????oTestResult.Assert?
" String " ? = ? " String " ,? " 字符串不相等 "
End?Sub

Public ? Sub ?TestLong(oTestResult? As ?TestResult)
????oTestResult.AssertEqualsLong?
1 ,? 456 ,? " 數值不相等 "
End?Sub

在窗體中要將Runner和類進行綁定,建議的類名前綴為TC,新增的測試函數一定要在ITestContainer_TestCaseNames中進行注冊,新增的測試函數一定要有oTestResult As TestResult這個聲明,而且只能有這么一個聲明。

還有就是要在IDE的選項中,將錯誤捕獲改為“遇到未處理的錯誤時中斷”就可以享受VB6下邊的單元測試了。

參考文章:
http://champion.ewuxi.com/old/XP/xppractice/vbunit.htm
http://www.soho-works.net/BLOG/313.asp
http://comunit.sourceforge.net/?page=tutorial.html

VB6-單元測試工具ComUnit


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!?。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 麻豆国产在线不卡一区二区 | 天天色播 | 欧美精品久久久久久久免费观看 | 美女18毛片免费视频 | 精品福利国产 | 91这里只有精品 | 国产福利在线观看精品 | 深夜福利视频网站 | 国产成人无精品久久久久国语 | 97超视频在线观看 | 中文字幕在线观看不卡视频 | 欧美一级久久久久久久大 | 伊人久久色| 毛色毛片免费看 | 国产在线精品一区二区 | 欧美顶级毛片在线播放 | 久久精品国产亚洲片 | 一级女毛片 | 欧美日韩一二三 | 亚洲国产日韩欧美一区二区三区 | 欧美经典人人爽人人爽人人片 | 久久天天躁夜夜躁狠狠85麻豆 | 免费欧美日韩 | 日本1区2区3区 | 色狠狠狠狠综合影视 | 五月婷婷开心综合 | 尤物视频在线播放 | 精品亚洲成a人7777在线观看 | 国内精品美女久久久久 | 日韩欧美综合视频 | 亚洲国产欧美日韩一区二区三区 | 超激情碰碰碰啪在线视频 | 欧美亚洲国产精品久久第一页 | 99久久免费视频在线观看 | 中日韩欧美中文字幕毛片 | 九九福利 | 久久黄色一级视频 | 成人国产激情福利久久精品 | 久久亚洲精品玖玖玖玖 | 日韩毛片在线影视 | 成人私拍福利视频在线 |