VB6-Modify comunit (exempt from registration of case names)

Source: Internet
Author: User

In the process of testing-driven development, writing test cases is cumbersome, but more complicated is the process of testing using the comunit framework, you need to register the name of the test case frequently.Code:

' 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 ()
End Property

This is good, but the process of registering, deleting, and modifying the name of the test case is troublesome. It takes a lot of time to change the name. After a long time, the array will be long, on the way home on the weekend, he began to read the refactoring book. Martin Fowler mentioned that in the JUnit framework, if the name of the test case is fixed prefix, you don't need to register the name of the test case frequently. Well, this method is good. At least I am a lazy. After research, using TLI can easily implement this reflection usage in VB6, the Code is as follows: ' 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 ()
Itestcontainer_testcasenames = Autogettestcasenames
End Property

' Auto get testcasenames
' Testcasename prefix must is "test _"
Private   Function Autogettestcasenames () As Variant ()
Dim Typelib As   Object
Dim Prop As   Object
Dim I As   Integer
Dim Vhas As   Boolean
Dim V () As Variant
Set Typelib =   Createobject ( " TLI. tliapplication " )
Set Typelib = Typelib. interfaceinfofromobject (me)
For   Each Prop in typelib. Members
If Prop. invokekind = Invoke_func Then
If   Ucase (VBA. Left (prop. Name, 5 )) =   Ucase ( " Test _ " ) Then
If Vhas =   False   Then
Vhas =   True
Redim Preserve V ( 0 )
Else
Redim Preserve V ( Ubound (V) +   1 )
End   If
V ( Ubound (V )) = Prop. Name
End   If
End   If
Next
Set Typelib =   Nothing
Set Prop =   Nothing
On   Error   Goto Onerrors:
Autogettestcasenames = V
Exit   Function
Onerrors:
Autogettestcasenames =   Array ()
End Function

The test cases are as follows: Public   Sub Test_ver (otestresult As Testresult)
With Otestresult
F. config app. Path &   " \ Testmatter \ fileclass \ ver.exe "
. Assert F. Ver () =   " 2.0.0.30 " , " 0001 "
F. config app. Path &   " \ Testmatter \ fileclass \ ver.txt "
On   Error   Goto Onerrors
F. Ver
. Assert False , " 0002 "
Onerrors:
End   With
End sub

Using all the test cases starting with test _ in this Code, the system will automatically discover that you do not need to register the name of the test case frequently. It feels great.

Now, I feel the beauty of open source. Many small functions can be modified and used comfortably.

Drip:

I have read the refactoring book several times before, and each time I get new results. Recently, after using comunit for development, the efficiency is really good, and the development method has changed in essence, test-driven development can be enjoyed only after practice.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.