Skip to content
JoepGeeversPublic

About

Quickly create an instances of your class for testing without being bothered with constructor parameters

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

52 Commits

Folders and files

Repository files navigation

Ninstance

Create constructor agnostic test instances on the fly, in the blink of an eye...

Use

// arrange
var service = Instance.Of<FavouriteSongService>();

// act

instead of

// arrange
var service = new FavouriteSongService(
    new ThisService(),
    new ThatService(),
    new ActuallyUsefulService(),
    new AddedService(),
    new ForgottenService(),
    new VeryImportantService(),
    new DontCareService()
);

// act

and never look back. Ninstance will instantiate FavouriteSongService with substitutes. Stop fixing hundreds of tests when you change the signature of it.

Or, when you do want to pass dependencies, just do

// arrange
var actuallyUsefulService = Substitute.For<IActuallyUsefulService>();
    actuallyUsefulService.Jump().Returns(true);

var veryImportantService = new VeryImportantService>(42);

var service = Instance.Of<FavouriteSongService>(actuallyUsefulService, veryImportantService);

// act

instead of

// arrange
var actuallyUsefulService = Substitute.For<IActuallyUsefulService>();
    actuallyUsefulService.Jump().Returns(true);

var veryImportantService = new VeryImportantService(42);

var service = new FavouriteSongService(
    new ThisService(),
    new ThatService(),
    actuallyUsefulService,
    new AddedService(),
    new ForgottenService(),
    veryImportantService,
    new DontCareService()
);

// act

and move on.

About

Quickly create an instances of your class for testing without being bothered with constructor parameters

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages