1.1.2 • Published 2 years ago

ecfeed v1.1.2

Weekly downloads
2
License
EPL-1.0
Repository
github
Last release
2 years ago

Integration with Node.js

Introduction

The following tutorial is an introduction to the Node.js runner. Note, that it does not cover the ecFeed basics. Therefore, if you want to learn how to create a sample model and generate a personal keystore, visit the tutorial section on our webpage.

Prerequisites:

  • Install the Node.js framework.
  • Download an IDE. For example Visual Studio Code.
  • Create a test model on the ecFeed webpage.
  • Generate a personal keystore named 'security.p12' and put it in the ~/.ecfeed/ directory (Linux users) or in the ~/ecfeed/ directory (Windows users).

For the full documentation check the source directly at GitHub.

Installation

Inside a new folder open a terminal and type 'npm init'. The command creates a new Node.js project.

The ecFeed library can be found online in the NPM repository. To include it in the project, type 'npm install ecfeed'.

Examples

Methods, used in the tutorial, are available in a welcome model, created during the registration process at the 'ecfeed.com' webpage. It the model is missing (e.g. it has been deleted by the user), it can be imported from here.

const TestProvider = require('ecfeed').TestProvider;

execute = async () => {
 
    const testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX");

    for await (const response of testProvider.exportNWise('QuickStart.test')) {
        console.log(response);
    }

}

execute();

To execute the code, type 'node index.js' in the terminal.

Don't hesitate to experiment with the code and modify the welcome model. It can be recreated easily and there is no better way to learn than hands-on exercises.

However, have in mind that the ID of every model is unique. If you want to copy and paste the example, be sure to change it accordingly.

Feedback

To send feedback, you need to have a BASIC account type or be a member of a TEAM.

An example looks as follows:

const testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX");
const method = 'QuickStart.test';

const data = [];

before(async () => {
    for await (const response of testProvider.generateNWise(method, { feedback:true, label:'NWise'})) { 
        data.push(response) 
    }
})

it('Mocha tests', () => {
    describe('Default', async () => {
        forEach(data).it("NWise", (arg1, arg2, arg3, testHandle) => { 

            if (arg1 >= 2) {
                testHandle.addFeedback(false, { comment: "Incorrect 'arg1'" });
                assert.fail();
            } else {
                testHandle.addFeedback(true);
            }

        });
    })
})

To the generation method an additional argument, i.e. 'TestHandle testHandle', must be added. The class consists of one public method, namely 'addFeedback'. The required argument denotes the result of the test, everything else is optional.

testHandle.addFeedback(true, { comment: 'Passed', duration: 1000, custom: {} })

status - The result of the test. comment - The optional description of the execution. duration - The optional execution time in milliseconds. custom - The optional object consisting of custom key-value pairs.

Note, that each test must return a feedback, regardless whether it has passed or failed. Only the first execution of the 'addFeedback' takes effect. All subsequent executions are neglected.

Additionally, to the test generation method one optional argument can be added, namely 'label'. It provides a short description of the generated test suite.

TestProvider class API

The library provides connectivity with the ecFeed test generation service using the 'TestProvider' class. It requires the model ID, the keystore location, the keystore password, and the generator service address.

Constructor

The 'TestProvider' constructor takes one required and three optional arguments (as object fields).

  • model (required) - The model ID. It is a 20 digit number (grouped by 4) that can be found in the 'My projects' page at 'ecfeed.com'. It can be also found in an URL of the model editor page. It's value can be changed later using the 'Model' property. For example:
testProvider.model = "XXXX-XXXX-XXXX-XXXX-XXXX";
  • keyStorePath - The path to a keystore downloaded from 'ecfeed.com' webpage ('Settings' -> 'Security'). The keystore contains the user certificate which is needed to authenticate the user at the generator service. By default, the constructor looks for the keystore in ~/.ecfeed/security.p12, except for Windows, where the default path is ~/ecfeed/security.p12.
  • keyStorePassword - The password for the keystore. The default value is 'changeit' and this is the password used to encrypt the keystore downloaded from the 'ecfeed.com' page.
  • generatorAddress - The URL of the ecfeed generator service. By default it is 'gen.ecfeed.com'.

Creating a TestProvider object can look like this:

TestProvider testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX");
TestProvider testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX", { keyStorePath: '', keyStorePassword: '', generatorAddress: ''});

Generator calls

'TestProvider' can invoke four methods to access the ecFeed generator service. They produce parsed, and streamed data.

async *generateNWise(method, userData = {})

Generate test cases using the NWise algorithm.

Arguments:

  • method (required) - The full name of the method that will be used for generation (including the namespace). If the method is not overloaded, its parameters are not required.
  • n - The 'N' value required in the NWise algorithm. The default is 2 (pairwise).
  • coverage - The percentage of N-tuples that the generator will try to cover. The default is 100.
  • choices - A dictionary in which keys are names of method parameters. Their values define a list of choices that should be used during the generation process. If an argument is skipped, all choices are used. For example:
choices: {'arg2': ['choice1', 'choice2']}
  • constraints - A list of constraints used for the generation. If not provided, all constraints are used. For example:
constraints: ['constraint']

Additionally, two string values can be used instead:

constraints: 'ALL'
constraints: 'NONE'
  • feedback - A flag denoting whether feedback should be sent beck to the generator. By default, this functionality is disabled.
  • label - An additional label associated with feedback.
  • custom - An additional object with custom elements associated with feedback.

async *generateCartesian(method, userData = {})

Generate test cases using the Cartesian product.

Arguments:

  • method (required) - See 'generateNWise'.
  • choices - See 'generateNWise'.
  • constraints - See 'generateNWise'.
  • feedback - See 'generateNWise'.
  • label - See 'generateNWise'.
  • custom - See 'generateNWise'.

async *generateRandom(method, userData = {})

Generate randomized test cases.

Arguments:

  • method (required) - See 'generateNWise'.
  • length - The number of tests to be generated. The default is 1.
  • duplicates - If two identical tests are allowed to be generated. If set to 'false', the generator will stop after creating all allowed combinations. The default is 'true'.
  • adaptive - If set to true, the generator will try to provide tests that are farthest (in the means of the Hamming distance) from the ones already generated. The default is 'false'.
  • choices - See 'generateNWise'.
  • constraints - See 'generateNWise'.
  • feedback - See 'generateNWise'.
  • label - See 'generateNWise'.
  • custom - See 'generateNWise'.

async *generateStatic(method, userData = {})

Download generated test cases (do not use the generator).

Arguments:

  • method (required) - See 'generateNWise'.
  • testSuites - A list of test case names to be downloaded. For example:
testSuites: ['default']

Additionally, one string value can be used instead:

testSuites: 'ALL'
  • feedback - See 'generateNWise'.
  • label - See 'generateNWise'.
  • custom - See 'generateNWise'.

Export calls

Those methods look similarly to 'generate' methods. However, they do not parse the data, and generate the output using templates. For this reason, they require one more argument, namely 'template'. It is located at the end argument list and predefined values are: 'XML', 'JSON', 'Gherkin', 'CSV', and 'Stream'. The default value is 'CSV'.

Have in mind that it is also possible to define a custom template. The instruction on how to do it can be found on the ecFeed webpage.

The methods are as follows:

async *exportNWise(method, userData = {})
async *exportCartesian(method, userData = {})
async *exportRandom(method, userData = {})
async *exportStatic(method, userData = {})

For example:

const TestProvider = require('./TestProvider').TestProvider;

for await (const response of testProvider.export(method, { dataSource: generator.nwise, template: TestProvider.csv })) {
    console.log(response);
}

Other methods

The following section describes additional methods.

validateConnection()

Verifies if the connection settings (including the keystore) are correct. If something is wrong, an exception is thrown.

async getMethodTypes(method)

Gets the types of the method parameters in the on-line model.

async getMethodNames(method)

Gets the names of the method parameters in the on-line model.

0.1.0

2 years ago

1.1.1

2 years ago

1.1.2

2 years ago

1.1.0

3 years ago

1.0.0

4 years ago