/Tessl

Tessl is a Testability-focused Extremely Simple Service Locator. It aims to be the simplest possible way to make a component with dependencies testable. This is a C# implementation in one .cs file

Primary LanguageC#

Tessl is a Testability-focused Extremely Simple Service Locator.

It is intended to provide the simplest possible service locator that can make a component with dependencies testable. It is suitable for:

  • Making legacy code with hard-wired dependencies testable with minimal change. Hard-wired dependencies can be replaced with tesslated dependencies by a relatively simple search and replace.
  • Writing testing code in the absence of a dependency injection framework, and with the least possible configuration - none at all.

How Simple?

It has no configuration file and no registry. Requires minimal change to production code. Requires one line of code to setup in a test fixture Works with your favourite Mocks or with stubs

What will my tesslated production code looke like? Will it first requires hours of rewriting?

Tesslated Constructors RequiredType1 dependencyByConstructor = new RequiredType1(arg1, arg2); becomes: RequiredType1 dependencyByConstructor = Tessl.New(arg1, arg2);

Tesslated Factory Methods

RequiredType2 dependencyFromFactoryMethod = FactoryClass.FactoryMethod(arg1, arg2); becomes: RequiredType2 dependencyFromFactoryMethod = Tessl.From<ParamType1, ParamType2, RequiredType2>( FactoryClass.FactoryMethod, arg1, arg2);

Tesslated Object Initializers

RequiredType3 dependencyFromObjectInitializer = RequiredType3 { Prop1=value1, Field1=value2 }; becomes: RequiredType3 dependencyFromIbjectInitializer = Tessl.Init( RequiredType3 { Prop1=value1, Field1=value2 });

How do I use it with MyFavouriteMockingFramework?

//Arrange var mock= MyFavouriteMockingFramework.Mock.Object; Tessl.Configuration= mock; mock.Setup( x => x.New ).Return( mockDependency ); //Tessl will injects mock where your pre-tesslated code had a hard-coded constructor call

//Act var unitUnderTest = new UnitUnderTest(); unitUnderTest.MethodUnderTest();

//Assert Assert.IsTrue( whateverYouWantedToAssert );

If you can help to achieve simplicity, please join in.