Skip to content

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

License

Notifications You must be signed in to change notification settings

JoepGeevers/Ninstance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages