Do you like your unit tests concise and readable? Do you enjoy using xUnit and Moq? Then Nukito is for you!
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.
Get it from the NuGet gallary.
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");
}
- A basic example
- Requesting mocks via the constructor
- Working with contexts
- Configuring mock settings
- Requesting the MockRepository
All the examples and the test domain can be found here.
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.