Manual
index > documentation > manual
Simply test represents a pythonic script with a special XML manifest. Both of them must be placed in %ratm_path%/tests
directory or in it's subdirectories. Now let's create a simple test.
Create a python file in the %project_path%/autotests as shown in the example below:
Example (passed_example.py):
00001| #!/usr/python
00002| # -*- coding: utf-8 -*-
00003|
00004| print( "TEST PASSED" );
Note: If the string "TEST PASSED" was found in the stdout, then test is considered to be passed successfully.
Then let's create manifest for this test. It may looks like in the example below:
Example (passed_example.xml):
00001| <?xml version="1.0" encoding="utf-8"?>
00002| <root>
00003| <author name="tester's name" email="tester@localhost"/>
00004| <description value="dsc"/>
00005| <label value="tag"/>
00006| <timeout value="10"/>
00007| <type value="py"/>
00008| <execution_count value="5"/>
00009| <format value="html_format"/>
00010| </root>
Here tag author contains informathion about test-case's author (attribute "author"), author's email
(attribute "email"). Tag description contains test case description. Tag timeout contains information about maximum time (in seconds)
wich is granted for the test. If the execution time exceeds this timeout then test-case is concidered to be finished with
error. Tag label contain comma separted tags for this test. Each test will be executed N times (here N is stored in attribute "value"
of the tag execution_count. In the example above it is equal to 5. If there is no tag execution_count then N will be defaulted to 1).
Tag format is responsible for log formatting modes. If it's attribute 'value' is set to html_format then all white spaces and "\n" symbols will be replaced
with and <br /> respectively (see reference for more information about -html_format command line option).
Well, all preparations are finished and we can start testing:
Note: that all command line options wich are passed to the run.py script will also be passed to the 'py' and 'cmd' tests.
After this you will find file autotest_log.html in RaTM root directory.
Integration is very simple. To do it just create manifest for your tests as described in the previous chapter, but set type of the test equal to 'unittest'.
If your modules are written not in Python but in other language, you still can use RaTM. There is a way to
load binary modules using ctypes Python library.
Note: ctypes is available for Python 2.5 and later.
First of all create manifest like in the examle above. Then create script wich will test your module:
Example (windows_example.py):
00001| #!/usr/python
00002| # -*- coding: utf-8 -*-
00003|
00004| import ctypes
00005|
00006| lib = ctypes.CDLL( "kernel32" );
00007| print( lib.GetModuleHandleA( None ) );
00008|
00009| print( "TEST PASSED" );
Now you can run your scripts:
cmd>python run.py -l ctypes
That's all.
Python ctypes documentation available here.
RaTM provides abilities to test web-applications. It allows you to test web-apps wich are written in different languages. Such tests can be run using next manifest:
Example (http_example.py):
00001| <?xml version="1.0" encoding="utf-8"?>
00002| <root>
00003| <author name="tester's name" email="tester@localhost" />
00004| <label value="http" />
00005| <timeout value="10" />
00006| <type value="simple_http" />
00007| <host value="localhost" />
00008| <url value="/http_test.php" />
00009| <method value="POST" />
00010| <description value="Description" />
00012| <format value="" />
00012| </root>
RaTM also provides more complex abilities for sending requests to the HTTP server (file
%ratm_path%/core/http_utilities.py). So you can run tests wich are created using any server side
language. Such as PHP, Perl, Python, ASP etc. Manifest's sintax is shown in the next example
(file http_test.php can be found in the %ratm_path%/misc):
Example (http_example.py):
00001| <?xml version="1.0" encoding="utf-8"?>
00002| <root>
00003| <author name="tester's name" email="tester@localhost" />
00004| <label value="http" />
00005| <timeout value="10" />
00006| <type value="http" />
00007| <host value="localhost" />
00008| <url value="/http_test.php" />
00009| <method value="POST" />
00010| <description value="Description" />
00011| <test_id value="0,1,4,6" />
00012| <format value="" />
00012| </root>
Note: All ampersants in field 'value' of the tag 'url' must be replaces with {amp} macro.
Note that in this example format tag is set to "". It was done because of that reasons that
logs for http tests are already well formatted for visualisation and any extra formatting can break it's HTML structure.
Using this manifest run.py will send requests to the server. Your server-side script must handle all
two types of these requests. It uses first request to get
total count of subtests (parameter 'action' with value 'get_sub_test_count'). Next requests are
used to launch exact subtest (parameter 'action' with value 'run_sub_test', parameter 'test_id' with
the subtest's identificator from the range [ 0 , sub_test_count - 1 ]). If an error occured while request
processing then the response 'Illegal request parameters' is expected. There is one more command is
this protocol: 'get_sub_test_name' with parameter 'test_id'. Server should return name of the subtest with id 'test_id'.
Tag test_id is optional and contain list of subtest's identificators. If tag test_id was found in the test's manifest
then only those subtests will be run wich id was found in the manifest's list of identificators.
Running tests from command line is very simple. The example of the manifest is shown here:
Example (cmd_example.xml):
00001| <?xml version="1.0" encoding="utf-8"?>
00002| <root>
00003| <author name="tester's name" email="tester@localhost" />
00004| <label value="cmd" />
00005| <timeout value="60" />
00006| <type value="cmd" />
00007| <cmd value="python.exe run.py -l passed" />
00008| <description value="Description" />
00009| <execution_count value="5" />
00010| </root>
Here you can find only one new tag - cmd. In it's attribute 'value' path to the running executable and startup parameters are defined.
You can create a manifest and put there all settigs for you testing project like it was done in the next example:
Example (project.xml):
00001| <?xml version="1.0" encoding="utf-8"?>
00002| <root>
00003| <project_path value="../" />
00004| <tests_path value="./tests/" />
00005| <bin_modules_path value="#project_path#lib/" />
00006| <workspace_path value="./workspace/" />
00007| <core_path value="./core/" />
00008| <send_logs value="-cls#-show_log#-external#-blank" />
00009| </root>
Sintax is very simple:
- project_path - this is path to the project wich will be tested by RaTM
- tests_path - path to the directory where all tests are put
- bin_modules_path - path to the application (or any other) binaries wich will be tested
- workspace_path - path to the temporary directory (if it does not exists then it will be created)
- core_path - path to the RaTM's core
- extra_params - all other command line parameters
This project allows you to start testing in a very simple way:
Example:
cmd>python.exe -project project.xml
You can also specify tag http (if you are testing your web applications). It may have up to 4 attributes - host,
path (to the script in http request), login and password. And when you are executing your http unit-tests all
macro {login}, {password}, {path} and {host} in test's manifest file (value attributes of the url and host tags) will be replaced with the
corresponding value from the projest's manifest.
Note: This functionality is not available for Python v 2.1 and lower.
After all tests has been finished, testing logs may be sent to testers. It will be done if you will set command line
option -send_logs. All email addresses will be extracted from test's manifests (tag author attribute email). But there is
a way to define extra email addresses of people wich are intrested in viewing results of each testing, but who does not write tests at all. It can be developers or team leads,
you can also add email of your CEO )). These emails and other parameters acan be defined in the testing project's manifest. Just add tag send_email with
attribute extra_emails and write there a comma separated list of emails. There are two other attributes for this tag: email_server_host
and email_server_port. There are email server's host and port are stored. If they are not defined then their values will be defaulted to 'localhost' and 25 respectively.
Zip archive with all testing logs can backuped on FTP server. To enable this functionality set command line parameter option -send_logs_ftp
and add tag send_logs_ftp in testing project manifest. It should have 5 attributes ftp_server_host, ftp_server_port,
ftp_server_dir, ftp_user and ftp_password.
|