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:
For complete documentation check the source directly at GitHub.
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'.
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.
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)
})
})
})
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.
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.
The 'TestProvider' constructor takes one required and three optional arguments (as object fields).
testProvider.model = "XXXXX-XXXXX-XXXXX-XXXXX";
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: ''});
'TestProvider' can invoke five methods to access the ecFeed generator service.
Generate test cases using the NWise algorithm.
Arguments:
choices: {'arg2': ['choice1', 'choice2']}
constraints: ['constraint']
Additionally, two string values can be used instead:
constraints: 'ALL'
constraints: 'NONE'
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'.
Generate test cases using the Cartesian product.
Arguments:
Generate randomized test cases.
Arguments:
Download generated test cases (do not use the generator).
Arguments:
testSuites: ['default']
Additionally, one string value can be used instead:
testSuites: 'ALL'
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);
}
The following section describes additional methods.
Verifies if the connection settings (including the keystore) are correct. If something is wrong, an exception is thrown.
Gets the types of the method parameters in the on-line model.
Gets the names of the method parameters in the on-line model.