Giter Club home page Giter Club logo

testing-tools's Introduction

What is NVerify?

This project is a simple library to wrap the NUnit (extensible to MSTest) assertion libraries in order to provide an expressive API for declaring unit-test assertions.

Why another .Net fluent assertion library?

When I made this library, there was only 1 other option, which I did not like, because it lacked flexible assertions for IEnumerable objects and methods. So I created this one, it has grown a bit through time. It still needs more tests, but is quite complete and can be used in any assertion scenario.

Features

  • It provides fluent assertions over:
    • Strings
    • Numbers
    • Arrays
    • Enumerables
    • Objects
    • Action<T,T1,T2...T15>
    • Func<T1,T1,T2...T15>
  • It can be used to define to check for thrown Exceptions.
  • It includes some functions like: Get file from current directory
    • If you have ever tried to read a data file from the current testing directory, you understand what I mean.
  • You can assert over the Properties of an object under test, not just the object itself.

How to get it

This tool is provided as a NuGet package, search for it using the name: [Testing Tools] (https://nuget.org/packages/TestingTools/)

You can also install it from the command line: c:\project\dir\path> nuget install NVerify

TODO: Add example usage of every feature.

Usage

This tool is meant to be used in the Arrange/Act/Assert pattern, like in the following example:

using NVerify;
using NUnit.Framework;

[Fixture]
public class CalculatorTest
{
  [Test]
  public void TestCalculatorSum()
  {
    // Arrange
    Calculator target = new Calculator();
    int expected = 4;
    int result;

    // Act
    result = target.Sum(2, 2);

    // Assert: Should Pass
    Verify.That(result)
          .IsEqualTo(expected);
          .Now();
  }

  [Test]
  public void TestCalculatorSum2()
  {
    // Arrange
    Calculator target = new Calculator();
    int result;

    // Act
    result = target.Sum(2, 2);

    // Assert: Should Pass
    Verify.That(result)
          .IsLessThan(5)
          .And()
          .IsGreaterThan(3)
          .Now();
  }

  [Test]
  public void TestThrowsException()
  {
    // Arrange
    var target = new Calculator();
    int result;

    // Act
    var act = () => target.Sum(Int.MaxValue, 1);

    // Assert: Should Pass
    Verify.That(act).ThrowsException().Now();
  }

  [Test]
  public void TestArrayElements()
  {
    // Arrange
    var array = new int[] { 2, 3, 4 };

    // Assert: Should Pass
    Verify.That(array).DoesContain(2)
          .Now();

    Verify.That(array).DoesNotContain(1)
          .Now();
  }

  [Test]
  public void TestConsoleOutput()
  {
    // Arrange
    string expected = "Hello World!";

    // Act
    Action act = () => Console.Write("@Hello World!");

    // Assert: Should Pass
    Verify.That(act).WritesToConsole(expected)
          .Now();
  }

  [Test]
  public void TestExactConsoleOutput()
  {
    // Arrange
    string notExpected = "Hello World!";

    // Act
    Action act = () => Console.Write("@Hello World!");

    // Assert: Should Pass
    Verify.That(act)
          .DoesntWriteExactlyToConsole(notExpected)
          .Now();
  }
}

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.