Skip to content

yln/Nukito

Repository files navigation

Why ?

Do you like your unit tests concise and readable? Do you enjoy using xUnit and Moq? Then Nukito is for you!

What ?

Nukito lets you declare the SUT and mocks you need for testing as parameters of your test methods. It creates these objects for you which frees you from writing repetitive object creation and mock setup / verification code. It is similar to Jukito for Java.

Where ?

Get it from the NuGet gallary.

Show me !

The following compares a standard xUnit test with a Nukito unit test.

This is a basic example for an unit test using xUnit, Moq and Fluent Assertions.

[Fact]
public void FightWithoutNukito ()
{
  // Arrange
  var weapon = new Mock<IWeapon>();
  var samurai = new Samurai (weapon.Object);
  weapon.Setup (w => w.Name).Returns ("katana");

  // Act
  string result = samurai.Fight();

  // Assert
  result.Should().Be ("Samurai fights with katana");
  weapon.VerifyAll(); // Verifies invocation of getter (IWeapon.Name)
}

Adding Nukito to the mix results in the following equivalent test. Note that Nukito verifies all setup expectations for requested mocks by default.

[NukitoFact]
public void FightWithNukito (Samurai samurai, Mock<IWeapon> weapon)
{
  // Arrange
  weapon.Setup (w => w.Name).Returns ("nunchaku");

  // Act
  string result = samurai.Fight();

  // Assert
  result.Should().Be ("Samurai fights with nunchaku");
}

Examples

All the examples and the test domain can be found here.

Feedback

Did you encounter a bug or miss a feature? Create a new issue.
Do you want to give general feedback or help to spread the word? Rate or review Nukito at the NuGet gallary.

About

Auto mocking of test method parameters with xUnit and Moq.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages