Jython and Python
Grinder3 's scripting engine is Jython, which is the full implementation of Python in Java. Python learns to reference script Galleryand Richard perks ' tutorial. And the following sites: The Jython home page the Python language web site Ten python pitfalls
Recommend reading "Jython Essentials", can be free probation introductory chapter .
Scripting for the Grinder
Script Structure
To conform to the grinder framework, the script must follow the following conventions. The script must define a class named Testrunner
When a worker thread is started, the test script is run immediately. The script must define a class named Testrunner. The grinder engine then creates a Testrunner instance for each worker thread. The Testrunner instance of a thread can be used to store information Chengte the line.
Note
Although it is strongly recommended that you define the Testrunner class, Testrunner does not necessarily have to be a class. Refer to Hello world with functions. The Testrunner instance must be callable
A Python object is callable if the __call__ method is defined. Each worker thread executes several times on the test script and configures it according to the properties Grinder.runs. The Testrunner is invoked on each run,worker thread, so the __call__ method can be considered as a definition of a run. Test scripts can be accessed through the Grinder object
Engine creates an object named grinder for the script to import. It can also be import by any module called by the script. This is an instance of the Grinder.scriptcontext class and provides access to context environments such as worker thread IDs and services, such as logging and data statistics.
Canonical test Script structure standard test scripts schema
The following is an example of a script that conforms to the above rules. The script has simple features-every run records Hello World to output log.
From Net.grinder.script.Grinder Import Grinder
# An instance the ' This ' class is created for every thread.
Class Testrunner:
# This are called for every run.
def __call__ (self):
# per thread scripting goes here.
Grinder.logger.output ("Hello World")
automatically generating scripts automatically generate test scripts
If you want to create a script for a Web site or Web application, you can use tcpproxy to produce a Httpplugin test script that works for grinder.
Tests
Although the simple test script above can be used for the grinder framework and can be executed multiple times by several worker processes on multiple machines, it does not report any statistical data. Therefore, you need to create some tests. A test has a unique testing number and description.
A test is added to the script below:
From Net.grinder.script import Test
From Net.grinder.script.Grinder Import Grinder
# Create a test with a test number and a description.
test1 = Test (1, "Log method") # Test number and description
Class Testrunner:
def __call__ (self):
Log ("Hello World")
In the example above, a test is created, and the testing number is "1", which is described as "