The following tutorial is an introduction to the Java 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 the complete documentation check the source directly at GitHub.
The ecFeed library can be found online in the Maven Repository.
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 (and then imported) from here.
import com.ecfeed.TestProvider;
import com.ecfeed.TypeExport;
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
TestProvider testProvider = TestProvider.create("GA1C-N74Z-HKAT-6FMS-35EL"); // The model ID.
for (String chunk : testProvider.exportNWise("QuickStart.test", TypeExport.CSV)) { // The method name.
System.out.println(chunk);
}
}
}
Do not hesitate to experiment with the code and modify the welcome mode. 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 each model (including the welcome model) is unique. If you want to copy and paste the above example, be sure to update it accordingly.
The ecFeed library can be used to create test cases for JUnit, which is one of the most common testing frameworks for Java. It is possible, because generation methods return the 'Iterable<Object[]>' interface, which can be directly used as the data source.
public class JUnit5Test {
static Iterable<Object[]> testProviderNWise() {
TestProvider testProvider = TestProvider.create("GA1C-N74Z-HKAT-6FMS-35EL");
return testProvider.generateNWise("QuickStart.test");
}
@ParameterizedTest
@MethodSource("testProviderNWise")
void testProviderNWise(int arg1, int arg2, int arg3) {
System.out.println("arg1 = " + arg1 + ", arg2 = " + arg2 + ", arg3 = " + arg3);
}
}
It is also possible to use enums as arguments. To do so, they must be defined (and visible) somewhere in the project.
public class JUnit5Test {
enum Gender {
MALE, FEMALE
}
enum ID {
PASSPORT, DRIVERS_LICENSE, PERSONAL_ID
}
static Iterable<Object[]> testProviderNWise() {
TestProvider testProvider = TestProvider.create("GA1C-N74Z-HKAT-6FMS-35EL");
return testProvider.generateNWise("com.example.test.LoanDecisionTest2.generateCustomerData");
}
@ParameterizedTest
@MethodSource("testProviderNWise")
void testProviderNWise(String name, String firstName, Gender gender, int age, String id, ID type) {
System.out.println("name = " + name + ", firstName = " + firstName + ", gender = " + gender + ", age = " + age + ", id = " + id + ", type = " + type);
}
}
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.
The 'TestProvider' constructor takes one required and three optional parameters which can be provided in the form of a 'Map<String, String>'. If they are not provided, default values are used (which, for the vast majority of cases, are sufficient).
model - 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 the URL of the model editor page.
TestProvider testProvider = TestProvider.create("GA1C-N74Z-HKAT-6FMS-35EL");
keyStorePath - The path to the keystore downloaded from the 'ecfeed.com' webpage ('Settings' -> 'Security'). The keystore contains the user certificate which is needed to authenticate the user at the generator service. Be default, the constructor looks for the keystore in ~/.ecfeed/security.p12, except for Windows, where the default path is ~/ecfeed/security.p12.
Map<String, String> configProvider = new HashMap<>();
configProvider.put("keyStorePath", "testKeyStorePath");
TestProvider testProvider = TestProvider.create("GA1C-N74Z-HKAT-6FMS-35EL", configProvider);
keyStorePassword - The password for the keystore. The default value is 'changeit' which is the password used to encrypt the keystore downloaded form the 'ecfeed.com' page.
Map<String, String> configProvider = new HashMap<>();
configProvider.put("keyStorePassword", "testKeyStorePassword");
TestProvider testProvider = TestProvider.create("GA1C-N74Z-HKAT-6FMS-35EL", configProvider);
generatorAddress - The URL of the ecfeed generator service. By default, it is 'gen.ecfeed.com'.
Map<String, String> configProvider = new HashMap<>();
configProvider.put("generatorAddress", "testGeneratorAddress");
TestProvider testProvider = TestProvider.create("GA1C-N74Z-HKAT-6FMS-35EL", configProvider);
'TestProvider' can invoke five methods to access the ecFeed generator service. They produce data parsed to 'Object[]'. Additional parameters can be included in a configuration object (or a map).
Generate test cases using the NWise algorithm.
Arguments:
String[] constraints = new String[]{ "constraint" };
Map<String, String[]> choices = new HashMap<>();
choices.put("arg1", new String[]{ "choice1", "choice2" });
Param.ParamsNWise config = new Param.ParamsNWise()
.constraints(constraints)
.choices(choices)
.coverage(100)
.n(3);
testProvider.generateNWise("QuickStart.test", config)
Also, additional parameters can be passed using a map.
Map<String, Object> config = new HashMap<>();
config.put("n", "2");
config.put("coverage", "100");
String[] constraints = new String[]{ "constraint" };
config.put("constraints", constraints);
Map<String, String[]> choices = new HashMap<>();
choices.put("arg1", new String[]{ "choice1", "choice2" });
config.put("choices", choices);
testProvider.generateNWise("QuickStart.test", config)
If the configuration object/map is not provided, default values are used.
Calls n-wise with n=2. For people that like being explicit. Uses the same arguments as 'generateNWise' excluding 'n'.
Generate test cases using the Cartesian product.
Arguments:
Generate randomized test cases.
Arguments:
Download generated test cases (do not use the generator).
Arguments:
Those methods look similarly to 'generate' methods. However, they return the 'Iterable
public Iterable<String> exportNWise(String method, TypeExport typeExport, Param.ParamsNWise config);
public Iterable<String> exportPairwise(String method, TypeExport typeExport, Param.ParamsPairwise config);
public Iterable<String> exportCartesian(String method, TypeExport typeExport, Param.ParamsCartesian config);
public Iterable<String> exportRandom(String method, TypeExport typeExport, Param.ParamsRandom config);
public Iterable<String> exportStatic(String method, TypeExport typeExport, Param.ParamsStatic config);
The following section describes helper 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.