396
❘
CHAPTER 18
Using ironPython for APPlicAtion testing
Notice that the
__main__()
code begins with print
‘Loading clr‘
. It’s important to describe every
event that occurs in the test script. Otherwise, you won’t know where a script has failed during testing.
Make sure you describe the mundane acts of loading and unloading modules, as well as the actual tests.
The first test begins with a call to
CreateHeading()
with the test number and title. The code then
performs a test,
Account1 = Accounts()
in this case, calls
ShowValues()
to test the result, and
finishes with
CreateFooter()
. Almost all of the tests follow the same pattern.
The final test is a little different than the rest. To perform the test correctly, you must evaluate the
content of both
Account1
and
Account2
. This is a case where you can infer what is happening inside a
method with the test code. The method,
Transfer()
, could perform the task correctly with
Account1
,
but not with
Account2
, which would tell you something about the content of the method and where to
look for the problem.
This final bit of script also shows the flexibility of using the three functions presented earlier. By sepa-
rating the individual tasks into three parts, you can call the
ShowValues()
function multiple times
as needed. You might also consider creating a second form of
ShowValues()
to accept a comparison
string for output (the
print ‘\nAccount1 = 8500‘
part of the script).
Performing the dLL Test
It’s time to run the DLL test. If you configured your project using the techniques in Chapters 16 and 17,
you should be able to click Start Debugging (or press F5) to start the build process. During the build
process, the compiler checks your DLL for major errors.
After the DLL is built, the IronPython script runs. Remember that this script is running outside of
the IDE, so nothing it does will actually affect the performance of your code. The diagnostic tests
will run and provide the information shown in Figure 18-2.
Notice that the use of formatting, test numbers, titles, comparison values, and so on makes the test
results extremely easy to read. Of course, a large DLL could overwhelm the capacity of the console
to display information. In this case, you could just as easily send the output to a text file, HTML
page, or an XML file. The point is that the script makes it possible to view diagnostics about your
application almost immediately after you build it.
Do'stlaringiz bilan baham: |