This is a short description of python library to access ecfeed online service. For the latest and full documentation of the ecfeed module, please refer to the docstring of the ecfeed module or check the sources directly at github.
The module was developed and tested against python 3.6. In theory it should work with earlier versions of python as well.
EcFeed module is hosted at pypi.org and can be simply downloaded with pip3
command:
pip3 install ecfeed
The examples assume that the user has a valid keystore downloaded to '.ecfeed' folder ('ecfeed' in Windows) in his home directory and the accessed model contains called methods. The method should be available in a welcome model created at registration at ecfeed.com. If the model is not there it can be imported from here.
>>> from ecfeed import TestProvider, DataSource, TemplateType
>>> ecfeed = TestProvider(model='0168-4412-8644-9433-6380') #change model id to your model
>>> for line in ecfeed.export_nwise(method='QuickStart.test', n=3, template=TemplateType.Gherkin, coverage=10):
... print(line)
...
Scenario: executing test
Given the value of arg1 is <arg1>
And the value of arg2 is <arg2>
And the value of arg3 is <arg3>
When test is executed
Examples:
| <arg1> | <arg2> | <arg3> |
| 4 | 3 | 3 |
| 1 | 3 | 4 |
| 3 | 4 | 2 |
| 3 | 3 | 1 |
| 3 | 1 | 1 |
| 2 | 1 | 1 |
| 1 | 2 | 3 |
Try and experiment with following:
for line in ecfeed.export_pairwise(method='QuickStart.test', template=TemplateType.XML, coverage=10):
print(line)
for line in ecfeed.generate_cartesian(method='QuickStart.test', coverage=40, choices={'arg1':['choice1'], 'arg3':['choice2', 'choice4']}):
print(line)
for line in ecfeed.export_random(method='QuickStart.test', length=5, duplicates=True, adaptive=True, template=TemplateType.CSV):
print(line)
for line in ecfeed.export_static_suite(method='QuickStart.test', test_suites=['suite1'], template=TemplateType.XML):
print(line)
for line in ecfeed.generate_cartesian(method='QuickStart.test', coverage=40, choices={'arg1':['choice1'], 'arg3':['choice2', 'choice4']}):
print(line)
Pytest is one of most popular testing frameworks for python, and luckily it supports parameterized tests. Even more luckily, the format returned by ecfeed's TestProvider generators (called with no templates) is directly usable for pydoc tests. And by some crazy coincidence, the util functions in TestProvider class can be used in pydoc's decorator to provide argument names:
class TestedClass:
@pytest.mark.parametrize(ecfeed.method_arg_names(method_name='QuickStart.test'), ecfeed.generate_random(method='QuickStart.test', length=5))
def test_method_1(self, arg1, arg2, arg3):
print('method(' + str(arg1) + ', ' + str(arg2) + ', ' + str(arg3) + ')')
The ecfeed python module provides connectivity with the ecFeed online test generation service using the class TestProvider. The class needs a keystore generated at ecfeed.com page to authenticate and identify the user at the gen service.
TestProvider constructor takes 4 optional arguments:
~/.ecfeed/security.p12
, except for Windows, where the default path is $HOME/ecfeed/security.p12
.None
.The gen service url, keystore location and password are constant and can't be changed in object's lifetime. The model id is accessible and mutable at any time. Also, the model id can be provided explicitly to a generation function each time.
An example call to construct a TestProvider object can look like this:
import ecfeed
ecfeed = TestProvider(model='0168-4412-8644-9433-6380')
TestProvider provides 5 generator functions to access ecfeed generator service. The function generate
contains the actual code doing the call, but it is rather cumbersome in use, so the additional functions wrap it and should be used in the code. The generators yield tuples of arguments casted to their types in the model. The only required parameter is the method parameter that must represent the full name of the method used for the generation (full means including full class name). If the generator service responses with error, the function raises EcFeedError exception.
A convenient way to call nwise generator.
choices={'arg1' : [choice1, choice2], 'arg2' : [choice3]}
.constraints=['constraint1', 'constraint2']
.Calls nwise with n=2. For people that like being explicit. Uses the same arguments that nwise, excluding 'n'.
Generates all possible combinations of parameters (considering constraints).
Generates random combinations of method choices.
Downloads generated test cases (does not use the generator).
The generate
function accepts one more parameter, namely 'template'. If it is present (and not set to None
), it yield lines of text, exported by the ecfeed service according to the chosen template.
Templates are defined by the TemplateType enum, supported values are: CSV, JSON, Gherkin and XML. Check the docstring for details (TemplateType pydoc.doc(ecfeed.TemplateType)
) to check all supported export templates. The default is 'CSV'.
For convenience, similarly to the functions described int the previous paragraph, supplementary wrappers exist. The only difference is that they they are extended by the default value of the 'template' parameter.
Some other functions are provided to facilitate using TestProvider directly as data source in test frameworks like pytest.
Queries generator service for information about the method. Returns a dictionary with following entries:
Returns list of argument names of the method.
Returns list of argument types of the method.
The generator can also be accessed from the command line, for example:
ecfeed --model 0168-4412-8644-9433-6380 --method QuickStart.test --cartesian
These arguments must be always provided when invoking an ecfeed command.
Arguments related to connection and authorization to ecFeed server. In most cases the default options will be fine.
These arguments are valid only with NWise generator
These arguments are valid only with random generator.
These arguments are valid only with --static option.
These arguments are valid with all or only some data sources.