DDTster 0.1.0

Install-Package DDTster -Version 0.1.0
dotnet add package DDTster --version 0.1.0
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DDTster, 0.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

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 597 7/20/2018

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