Automate testing with Visual Basic 6.0

Source: Internet
Author: User
Tags contains implement manual writing connect odbc object model ole
Visual Summary: This article explores the possibilities of using Visual Basic 6.0 in test automation and lists some examples that are applied in practical work



Deficiencies of an existing automated testing tool


At present, an obvious fact in front of software test automation is that the tools currently available do not do what we want them to do; it is unrealistic to expect that any tool can fully support test automation for many different applications. Since it is difficult to find a test tool that fully meets the needs of test automation, and test automation tools are expensive, it is common practice to use a major automated test tool and then use traditional programming languages such as Java, C + +, and Visual Basic writes an automated test script to compensate for the deficiencies of the tool.


The advantages and limitations of two Visual Basic applications to automated testing


The reason that you can implement some of the better features of Visual Basic than the test automation tool is that it writes test scripts for actual projects, and that there is a fact that Visual Basic does exist that are more obvious than other programming languages to apply to test automation projects.
As we all know, Visual Basic is not a test tool, but it is a very popular software development language; The biggest advantage of using Visual Basic is that it is a very popular language, simple, easy to learn, and has a very broad base of users who understand basic language, Even for test engineers who are not familiar with visual Basic, it's easy to get a lot of relevant publications and materials.
Visual basic itself has features that support the testing process, for example, it has the ability to return important information about the test platform and the application being tested. Visual Basic shell functions and SendKeys functions enable you to start an application and manipulate its graphical user interface, and you can use Visual Basic to write some of the required scripts, such as loading a test application. The integrated Visual Data Manager in Visual Basic can directly connect to a database and view its data structure. In addition, Visual Basic can be used to test some background-operated applications, such as scripting access to initialization files (. ini files) and Windows registry. The application Interface (API) for accessing Windows from Visual Basic is very effective for manipulating the application under test and for reporting important information, and the Visual Basic language spends less time mastering and having higher programming efficiency than other current programming languages. Suitable for testing automation work required to quickly establish test scripts.
Because Visual Basic is not a professional test tool and therefore has its limitations, it first does not contain much of the functionality that is currently ripe for automated test tools, for example, Visual Basic does not itself provide defect reporting, test design, and document management capabilities ; It also lacks recording capabilities and any automated test settings, and to include these features in Visual Basic test Code requires manual writing of this partial feature code, and most of the current publications and materials on Visual Basic are for developers rather than testers. Nonetheless, there are basic ways to apply Visual Basic to automated test projects without much effort.


Three sets of tools that support test automation in Visual basic


Visual Basic 6.0 contains a set of tools that support testing without any coding, including rich wizards, visual data tools, and object browsers.
1 Wizards and templates
There are a number of wizards in visual Basic that you can use. One of the most useful wizards for testers is the Data Form Wizard, which creates a data window that connects to an access or an ODBC database that can be set up to view individual records individually or to bulk browse data records in a tabular format. A test tool that can be quickly customized and easy to use to check the contents of a database is thus implemented.
Not only can the form template quickly create a standard window, but it can also accompany these windows to generate source code, which can be applied in part or all to a customized window for testing, which is very effective for improving test efficiency.
In addition, some other wizards, such as the Data Object Wizard, the ActiveX Control Window Wizard can achieve the least amount of coding effort to create and configure some useful test objects.
2 Visual Data Manager
A visual Data Manager can quickly connect to an ODBC or OLE DB data source to view database structures, datasheets, views, and other basic objects. Through it to check the background database to implement database application testing. That is, if the application under test contains a database in SQL Server,sybase, Oracle, and access, you can check all of these databases through a visual Data manager without having to log in to the DBMS interface separately. By using Visual Basic as a common foreground database manager to manage a background database that is accessed with ODBC or OLE DB, you can save testing time for test engineers and the training time that may be spent on familiarity with these database products.
The visual Data Manager supports white box testing through database input and test SQL statements. It allows you to modify background data and even create new data objects such as data tables, stored procedures, and data views. Some of the SQL statements used to test data (often used to retrieve duplicate rows of data and expose defects related to integrity) can be created and executed here even if necessary.
3 Object Browser Browser
The Object Browser is another very useful Visual Basic tool that examines the properties and methods of object output and the necessary parameters, and testers can use this information to create validated and functional tests of these objects, especially for object-oriented testing, which is useful and effective.
The Object Browser can display a repository of custom COM objects that lists the properties, methods, and events of that object, which can be developed in any language that supports the COM object model. Setting an Object Browser to capture and view information about objects in a short time for a tester who lacks test training, of course, to set up Visual Basic test scripts to test the properties of objects, methods, events need to do some coding work.


The application of four Visual basic in automated test work


Here are some examples of using Visual Basic to implement test automation or related work with simple coding, such as recording test results information, simple GUI testing, and so on.


1 recording test information with a text file

 

Example 1

Open ' Testlog.txt ' for Input as #1 ' opens the record file

Print #1, FileDateTime ("C:\Windows\Calc.exe") ' records the date and time created by the test program

Print #1, FileLen ("C:\Windows\Calc.exe") ' records the length of the program being tested

Print #1, CurDir ' Records current directory path

Print #1, Environ ("windir") ' records the current Windows directory path

Print #1, now ' record Test start date and time

....... ' Record the test process information

Close #1 ' Closes the record file


One of the things that you often do during testing is to check your application's login files for error information, which is usually a text file, and it's easy to open and read them to any programming language using its own basic file manipulation functions. Another task is to record the test process information and test results, which essentially use the same function function as above: A simple recording method is to write the test results into a text file. The code shown in example 1 implements these logging capabilities.


2 GUI Functional Testing

 

Example 2
Shell ("C:\Windows\Calc.exe") ' Start calculator
For i = 1 to 100 ' Set the calculation loop
SendKeys I & "{+}", True ' send keystroke action to Calculator
Next i ' Add the value of each time I
SendKeys "=", True ' calculates sum



In the black box test, the implementation of automated testing to write test scripts to simulate the user's day-to-day operation input. The use of Visual Basic shell functions and SendKeys functions can be a simple and effective way to implement some GUI functional testing.
The code shown in Example 2 opens a Windows calculator and then sends the keystroke action to simulate user input and compute the sum of a series of values (1 to 100); the launcher invokes the Visual Basic Shell function. The SendKeys instruction is used to send keystroke actions to the application to simulate user input and compute results.



3 Reading and setting registry information

 

Example 3
Dim astrsettings () As String ' defines a variable
Lstsettings.clear ' Clear list Box contents
Astrsettings = GetAllSettings (testappname, txtsection) ' calls a private function to return to VB
' Registry information for private locations
For icount = 0 to UBound (astrsettings) ' by looping the registry information
' Show in list box
Lstsettings.additem astrsettings (icount, 0) & ":" _
& Astrsettings (icount, 1)
Next icount
Note: Testappname is the name of the application being tested



Testers often have to check the registry, which is a place to store important information such as application installation settings, options, and so on. Visual Basic 6.0 contains a number of new functional functions that can be returned from registry key-value locations reserved for Visual Basic application software. These functional functions simply set and return these registry key values, which are especially useful for testing applications developed in Visual Basic.
Example 3 shows that the code returns all registry information in the registry in "Hkey_current_user\vb and VBA program Settings\" and displays the information in a list box named Lstsettings. To access registry information from another location, you need to invoke the Windows API function.


Five summary


Thus, in order to make up for the deficiencies of the current automated testing tools, choose to write some test scripts or test aids in some programming languages to prove practical in practice, and visual Basic 6.0, because of its powerful features, easy to learn and easy to use, has a wide range of user base and other advantages to be applied to test automation is one of the more promising tools.
Reference bibliography
1 Software Test automation technology Mark Fewster & Dorothy Graham, Electronics publishing house, January 2000
3 Research methods of software engineering---practitioners (rgoer) s.press, Machinery Industry Press, September 2000
2 "Visual Bsaic 6 Technical Insider" (United States) Steven Holzner, Machinery Industry Press, April 1999





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.