Data Generators
Data generation is a key aspect of unit testing. Without good data generation, unit testing can be less than productive. To fill that gap, Fonteva created data generators that will allow you to generate Salesforce data – both standard and custom objects.
useDataGenerators - (line 24 below) - You can build your own data generators so that you can provide any data you want. If you want to use several data generators, provide a comma-separated list of those generators. Fonteva uses chance.js to generate data. (See http://chancejs.com/.) You can also provide datasets using a seed. (See http://chancejs.com/usage/seed.html.)
EventRegistrationFlowDetailsControllerSpec.js
const {
useDataGenerators,
LTEAttendee
} = require('mocha-fonteva-data-generator');
useDataGenerators();
The following is an example of setting a prefix value for attendee for the inject() method (fixed:{contactID:990}). It calls the test method with the Attendee object.
attendeeSelectionControllerSpec.js
@inject(LTEAttendee({fixed:{contactId:990}}))
The following randomly generates 1-5 attendees with random data., all with random data, It then calls your test method with an array of attendees. Even if you only create one, it will still send an array of objects.
@inject([LTEAttendee, 1, 5])
Example data generatorThe example generator will generate an event Attendee object. This includes all the information that is required for us to test the event by the Attendee object, including Salesforce IDs generated based on custom work done to ensure the IDs match the format Salesforce provides. You can override and build your own methods to create test data. You can generate every object that Fonteva has in their system, or you can create your own. lteAttendee.js If you want to generate an attendee and override a value without actually generating it, you can do the following:
Functions
chance generates a seed. After it is generated, you can provide chance with this same seed. This seed will generate the same data every time the test runs. This allows you to create data sets for different scenarios. |
Previous: Framework Adapters | Next: Calling Test Methods