DDTster 0.1.0

dotnet add package DDTster --version 0.1.0
NuGet\Install-Package DDTster -Version 0.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DDTster" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DDTster --version 0.1.0
#r "nuget: DDTster, 0.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DDTster as a Cake Addin
#addin nuget:?package=DDTster&version=0.1.0

// Install DDTster as a Cake Tool
#tool nuget:?package=DDTster&version=0.1.0

DDT(Data-Driven Testing) is alive!

Sample of usage DDT pattern with XUnit and NUnit libraries.

What is it?

In this solution I want to provide sample how to use external files, to provide highest code quality, by preparing thousands of unit tests in one simple XUnit, or NUnit test. In data attributes I used EPPlus.Core to read excel files! Thx a lot guys! That's my tutorial how I prepared my module to go life on production with minimal number of bugs, only with creating one simple, easy and readable unit test. That's just my extension to XUnit and NUnit to provide more and better (yeah I know, how it looks like, but I'm not vegan, hipster with lumberjack beard).

What do I get?

Nothing special just an idea, how to minimalize stress and hot fixes after relase.

How is it done?

I created simple Data Source Providers to read from mssql database, or excel spreadsheet (CSV provider, and another database providers are during implementation). Each attributes has 2 cases of usage, dynamic, where simple test case is provided to method as dynamic object, or strongly typed where we provide type as parameter in attribute.

XUnit

  • DbDataAttribute.cs

    • dynamic [DbData("data source=.;initial catalog=Test;integrated security=True;", "dbo.TestCases")]

    • strongly typed, or TestCase<Dto, Result> [DbData("data source=.;initial catalog=Test;integrated security=True;", "dbo.TestCases", typeof(CarInsuranceDetailTestCase))]

  • ExcelDataAttribute.cs

    • dynamic [ExcelData("TestSample.xlsx", "CarInsurance")]

    • strongly typed, or TestCase<Dto, Result> [ExcelData("TestSample.xlsx", "CarInsurance", typeof(CarInsuranceDetailTestCase))]

NUnit

  • DbTestCaseSourceAttribute

    • dynamic - [DbTestCaseSource("data source=.;initial catalog=Test;integrated security=True;", "dbo.TestCases")]

    • strongly typed, or TestCase<Dto, Result> - [DbTestCaseSource("data source=.;initial catalog=Test;integrated security=True;", "dbo.TestCases", typeof(CarInsuranceDetailTestCase))]

  • ExcelTestCaseSourceAttribute

    • dynamic - [ExcelTestCaseSource("TestSample.xlsx", "CarInsurance")]

    • strongly typed, or TestCase<Dto, Result> - [ExcelTestCaseSource("TestSample.xlsx", "CarInsurance", typeof(CarInsuranceDetailTestCase))]

Sample of usage

To present how use attributes, and DDT pattern in practice, I created simple factory to calculate Car Insurance.

XUnit

[Theory]
[ExcelData("TestSample.xlsx", "CarInsurance")]
public void InsuranceTestTestCase(TestCase<CarInsuranceDetailDto, decimal> testCase)
{
    //ACT
    var insuranceCost = _calculationFactory.Calculate(testCase.Case);

    //ASSERT
    Assert.Equal(testCase.Result, insuranceCost);
}

NUnit

[Test]    
[ExcelTestCaseSource("TestSample.xlsx", "CarInsurance")]    
public void InsuranceTestTestCase(TestCase<CarInsuranceDetailDto, decimal> testCase)
{    
   //ACT    
   var insuranceCost = _calculationFactory.Calculate(testCase.Case);
   
   //ASSERT
   Assert.AreEqual(testCase.Result, insuranceCost);
}

Blog

Soon I will finish post on my blog, how I used in practice very similar mechanism to create thousands of unit tests for risk calculation in my project for Fenergo.

Any Question?

If you want to know more, or just you want to use it in your project feel free to contact me, open an issue.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0 916 7/20/2018

First release with 2 attributes providing connection with Excel File and Database