KeywordEngine 1.1.0
See the version list below for details.
dotnet add package KeywordEngine --version 1.1.0
NuGet\Install-Package KeywordEngine -Version 1.1.0
<PackageReference Include="KeywordEngine" Version="1.1.0" />
paket add KeywordEngine --version 1.1.0
#r "nuget: KeywordEngine, 1.1.0"
// Install KeywordEngine as a Cake Addin #addin nuget:?package=KeywordEngine&version=1.1.0 // Install KeywordEngine as a Cake Tool #tool nuget:?package=KeywordEngine&version=1.1.0
KeywordEngine
The KeywordEngine is a keyword-driven framework execution engine for automating test cases. It can easily integrate with any C# unit testing frameworks like NUnit, XUnit, and MSTest.
At a Glance:
- Compatible with .NET Core 6+.
- Supports any C# unit testing frameworks like NUnit, XUnit, and MSTest.
- No external dependencies beyond standard base libraries.
- Maps parameters to scalar types, including
Enums
,Guid
,DateTimeOffset
, and nullable scalar types. - Supports additional keyword data/parameters using the
ITestContext
interface. - Automatically ignores unused and additional provided parameters.
- Supports custom DependencyInjection to resolve keyword dependencies via the
IDependencyResolver
interface. - Uses
InvariantCulture
for default parameter parsing.
Quick Start Example:
using System;
using KeywordEngine.Core;
using KeywordEngine.Test.Keywords;
using KeywordEngine.Abstraction;
using KeywordEngine.Models;
// Define keywords
internal class MyFirstActionKeyword : IActionKeyword
{
private readonly string _message;
public MyFirstActionKeyword(string message)
{
_message = message;
}
public Task<KeywordResponse> Execute()
{
Console.WriteLine(_message);
Console.WriteLine($"{nameof(MyFirstActionKeyword)} keyword executed.");
return Task.FromResult(new KeywordResponse
{
Status = ResponseStatus.Executed,
Message = $"{nameof(MyFirstActionKeyword)} keyword executed."
});
}
}
internal class MyFirstVerifyKeyword : IVerifyKeyword
{
public Task<KeywordResponse> Execute()
{
Console.WriteLine($"{nameof(MyFirstVerifyKeyword)} keyword executed.");
return Task.FromResult(new KeywordResponse
{
Status = ResponseStatus.Executed,
Message = $"{nameof(MyFirstVerifyKeyword)} keyword executed."
});
}
}
// Create test steps
var test = new TestCase
{
Id = 1,
Title = "Demo test",
Steps = new List<TestStep>
{
new TestStep
{
Title = "First Step",
Keyword = nameof(MyFirstActionKeyword),
Index = 0,
Parameters = new List<Parameter>
{
new Parameter
{
Name = "message",
Value = "Hello"
}
}
},
new TestStep
{
Title = "Second Step",
Keyword = nameof(MyFirstVerifyKeyword),
Index = 1,
Parameters = new List<Parameter>()
}
}
};
// Initialize dependency injection and import keywords
var testRunner = TestRunnerFactory.CreateTestRunner();
// Execute test
await testRunner.ExecuteAsync(test);
Enhanced Keyword and Test Runner Workflow
Centralized Dependency Injection
The framework now supports centralized dependency injection using DependencyResolverFactory
. You don't need to create dependency injection manually for every test case. Keywords and dependencies are automatically resolved.
Simplified Test Runner Creation
The TestRunnerFactory
simplifies test runner creation. It handles:
- Keyword Importing: Automatically imports keywords if not already done.
- Dependency Injection: Uses a singleton
IDependencyResolver
instance. - Result Publishing: Provides a default
ConsoleResultPublisher
or allows custom publishers.
Updated TestRunnerFactory
Example
public static class TestRunnerFactory
{
private static TestCaseRunner? _testCaseRunner;
public static TestCaseRunner CreateTestRunner()
{
if (_testCaseRunner == null)
{
var dependencyResolver = DependencyResolverFactory.CreateResolver();
if (Module.NoKeywords)
{
Module.Import(typeof(MyFirstActionKeyword).Assembly);
}
_testCaseRunner = new TestCaseRunner(
dependencyResolver: dependencyResolver,
testResultPublisher: new ConsoleResultPublisher());
}
return _testCaseRunner;
}
}
Custom Result Publisher
You can define a custom result publisher by implementing the ITestResultPublisher
interface. For example:
public class CustomResultPublisher : ITestResultPublisher
{
public Task PublishTestResultAsync(TestResult testResult)
{
// Custom publishing logic, e.g., save to a database or log
Console.WriteLine($"Publishing test result: {testResult.TestTitle}");
return Task.CompletedTask;
}
}
Using a Custom Result Publisher
var testRunner = new TestCaseRunner(
testResultPublisher: new CustomResultPublisher()
);
Benefits of the New Flow
Ease of Use:
- No manual keyword imports or dependency injection setup.
- Centralized and reusable DI logic.
Modular and Extensible:
- Easily extendable with custom publishers or additional keyword assemblies.
Robust Execution:
- Centralized exception handling and result publishing ensure consistent test execution.
Other Examples:
For more examples and use cases, please check Tests and Samples.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.