Code Monkey home page Code Monkey logo

nukito's Introduction

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.

nukito's People

Contributors

yln avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.