The following tutorial is an introduction to the C# 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:
directory (Linux users) or in the ~/ecfeed/ directory (Windows users).
For complete documentation check the source directly at GitHub.
Inside a new folder open a terminal console and type 'dotnet new console'. The command creates a new C# project.
The ecFeed library can be found in the NuGet repository. To add it to the project, type 'dotnet add package 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.
using System;
using EcFeed;
namespace Example
{
class Runner
{
public static void Main(string[] args)
{
TestProvider testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX"); // The model ID.
foreach(var element in testProvider.ExportNWise("QuickStart.test")) // The name of the method.
{
Console.WriteLine(element);
}
}
}
}
To execute the code, type 'dotnet run' 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 (including the welcome model) is unique. If you want to copy and paste the example, be sure to update it accordingly.
The ecfeed library can be used to create test cases for NUnit, which is one of the most common testing frameworks for C#. It is possible, because generation methods return the 'IEnumerable<object[]>' interface, which might be directly used as the data source.
Inside a new folder open the terminal and type 'dotnet new nunit'. This command creates a new C# test project.
using System.Collections;
using NUnit.Framework;
using EcFeed;
namespace exampleNUnit
{
[TestFixture]
public class UnitTest
{
static public IEnumerable DataInt = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX").GenerateNWise("QuickStart.test");
[TestCaseSource("DataInt")]
public void TestInt(int a0, int a1, int a2)
{
// ...
}
}
}
To run tests, type 'dotnet test'.
To send feedback, you need to have a BASIC account type or be a member of a TEAM.
A feedback example looks as follows:
using System;
using System.Collections;
using NUnit.Framework;
using EcFeed;
namespace exampleNUnit
{
[TestFixture]
public class UnitTest
{
static internal TestProvider testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX");
static internal string method = "QuickStart.test";
static public IEnumerable DataInt = testProvider.GenerateNWise(method, feedback:true);
[TestCaseSource("DataInt")]
public void TestInt(int a0, int a1, int a2, TestHandle testHandle)
{
System.Collections.Generic.Dictionary<string, string> customDic = new System.Collections.Generic.Dictionary<string, string>();
customDic.Add("key1", "value1");
customDic.Add("key2", "value2");
testHandle.addFeedback(true, comment: "Passed", duration: 1000, custom: customDic);
}
[TearDown]
public void TearDown()
{
TestHandle ecfeed = TestContext.CurrentContext.Test.Arguments[^1] as TestHandle;
ecfeed.addFeedback(
TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Passed,
comment:TestContext.CurrentContext.Result.Message);
}
}
}
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. This is the only required field.
comment - The optional description of the execution.
duration - The optional execution time in milliseconds.
custom - The optional dictionary 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.
Generated feedback can be analyzed on the 'ecfeed.com' webpage.
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.
testProvider.Model = "XXXX-XXXX-XXXX-XXXX-XXXX";
Creating a TestProvider object can look like this:
TestProvider testProvider = new TestProvider("XXXX-XXXX-XXXX-XXXX-XXXX");
'TestProvider' can invoke four methods to access the ecFeed generator service.
Generate test cases using the NWise algorithm.
Arguments:
Dictionary<string, string[]> choices = new Dictionary<string, string[]>();
choices.Add("arg1", new string[] {"choice1", "choice2"});
choices.Add("arg2", new string[] {"choice1"});
string[] constraints = new string[] { "constraint" };
Additionally, two string values can be used instead:
string constraints = "ALL";
string 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:
string[] testSuites = new string[] { "default" };
Additionally, one string value can be used instead:
string constraints = "ALL";
Those methods look similarly to 'Generate' methods. However, they return the 'IEnumerable
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:
public IEnumerable<string> ExportNWise( ... , Template template);
public IEnumerable<string> ExportPairwise( ... , Template template);
public IEnumerable<string> ExportCartesian( ... , Template template);
public IEnumerable<string> ExportRandom( ... , Template template);
public IEnumerable<string> ExportStatic( ... , Template template);
The following section describes non-crucial 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.