abouttutorialspricingterms

  • Quick start
  • Modelling and data generation (part 1)
  • Modelling and data generation (part 2)
  • Integration with Java
  • Integration with C++
  • Integration with C#
  • Integration with Python
  • Integration with Node.js

Documentation

  • General
  • Team work
  • Data modelling
  • Export templates
  • Generator request syntax
  • Generator responses in JSON format

Integration with Node.js

Contents

Introduction
Installation
Examples
Mocha
Feedback

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 VSCode.
  • Create a test model on the ecFeed webpage (or use the default one).
  • Generate a personal keystore named 'security.p12' and put it in the ~/.ecfeed/ directory (Linux users) or in the ~/ecfeed/ directory (Windows users).

For complete 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 in the NPM repository. To add it to the project, type 'npm install ecfeed'.

Examples

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

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

execute = async () => {
 
    const testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX");              // The model ID.

    for await (const response of testProvider.exportNWise('QuickStart.test')) {     // The name of the method.
        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.

Mocha

The runner can be used with common testing frameworks, e.g. Mocha. An example of the integration can be found below:

const TestProvider = require('ecfeed').TestProvider;
const forEach = require('mocha-each');

const data = [ ];

before(async () => {
    const testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX");
    const method = 'QuickStart.test';
        
    for await (const response of testProvider.generateRandom(method)) {
        data.push(response);
    }
    
})

it('Mocha tests', () => {
    describe('Test suite', () => {
        forEach(data).it("Test case", (p1, p2, p3) => {
            console.log(p1, p2, p3)
        })
    })
})



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. In each test, only the first invocation of the 'addFeedback' method takes effect. All subsequent invocations 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

Contents

Constructor
Generator calls
Export calls
Other methods



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 web 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 = "XXXXX-XXXXX-XXXXX-XXXXX";
  • 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("XXXXX-XXXXX-XXXXX-XXXXX");
TestProvider testProvider = new TestProvider("XXXXX-XXXXX-XXXXX-XXXXX", { keyStorePath: '', keyStorePassword: '', generatorAddress: ''});

Generator calls

'TestProvider' can invoke five methods to access the ecFeed generator service.

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 *generatePairwise(method, userData = {})

Calls the '2-wise' generation procedure. For people that like being explicit. Apart from 'n' (which is always 2 and cannot be changed), the method accepts the same arguments as 'generateNWise'.

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 value 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 value 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 value 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 'Raw'. 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 *exportPairwise(method, userData = {})
async *exportCartesian(method, userData = {})
async *exportRandom(method, userData = {})
async *exportStatic(method, userData = {})

For example:

const template = require('./constants').template;

for await (const response of testProvider.export(method, { dataSource: generator.nwise, template: template.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.